You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
704 B
Go

package district
import (
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"github.com/dgraph-io/ristretto"
)
var nameCache *ristretto.Cache
func init() {
nameCache, _ = ristretto.NewCache(&ristretto.Config{
NumCounters: 1024,
MaxCost: 10 * 1024 * 1024,
BufferItems: 64,
IgnoreInternalCost: true,
})
}
func getCachedDistrictItem(code string) (*svc.DistrictCacheItem, bool) {
v, ok := nameCache.Get(code)
if ok {
return v.(*svc.DistrictCacheItem), true
}
return nil, false
}
func cacheDistrictItem(code string, nameList []string) {
nameCache.Set(code, &svc.DistrictCacheItem{
Code: code,
NameList: nameList,
}, 1)
nameCache.Wait()
}