diff --git a/cache.go b/cache.go index f62407f..9ab7230 100644 --- a/cache.go +++ b/cache.go @@ -28,10 +28,22 @@ type Cache struct { lock sync.Mutex } -func cacheNew(filler cacheFiller) *Cache { +func cacheNew(fillfn interface{}) *Cache { c := new(Cache) c.cache = make(map[interface{}]interface{}) - c.filler = filler + ftype := reflect.TypeOf(fillfn) + if ftype.Kind() != reflect.Func { + panic("cache filler is not function") + } + if ftype.NumIn() != 1 || ftype.NumOut() != 2 { + panic("cache filler has wrong argument count") + } + c.filler = func(key interface{}) (interface{}, bool) { + vfn := reflect.ValueOf(fillfn) + args := []reflect.Value{reflect.ValueOf(key)} + rv := vfn.Call(args) + return rv[0].Interface(), rv[1].Bool() + } return c } diff --git a/web.go b/web.go index cdec323..7b35450 100644 --- a/web.go +++ b/web.go @@ -1141,8 +1141,7 @@ func showhonkers(w http.ResponseWriter, r *http.Request) { } } -var combocache = cacheNew(func(key interface{}) (interface{}, bool) { - userid := key.(int64) +var combocache = cacheNew(func(userid int64) ([]string, bool) { honkers := gethonkers(userid) var combos []string for _, h := range honkers {