Documentation ¶
Index ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Cache *freecache.Cache `json:"-" toml:"-"` // 本地缓存实例【必填】 Expire time.Duration `json:"expire" toml:"expire"` // 失效时间 【必填】 DisableMetric bool `json:"disableMetric" toml:"disableMetric"` // metric上报 false 开启 ture 关闭【选填,默认开启】 Name string `json:"-" toml:"-"` // 本地缓存名称,用于日志标识&metric上报【选填】 }
type LocalCache ¶
type LocalCache[K comparable, V any] struct { // contains filtered or unexported fields }
func New ¶
func New[K comparable, V any](c *Config) (localCache *LocalCache[K, V])
New 构建本地缓存实例 缓存容量默认256MB 最小512KB 最大8GB
func StdNew ¶
func StdNew[K comparable, V any](name string) (localCache *LocalCache[K, V])
StdNew 构建本地缓存实例 The entry size need less than 1/1024 of cache size
func (*LocalCache) GetAndSetCacheData ¶
func (c *LocalCache) GetAndSetCacheData(key string, id K, fn func() (V, error)) (value V, err error)
GetAndSetCacheData 获取缓存后数据
func (*LocalCache) GetAndSetCacheMap ¶
func (c *LocalCache) GetAndSetCacheMap(key string, ids []K, fn func([]K) (map[K]V, error)) (v map[K]V, err error)
GetAndSetCacheMap 获取缓存后数据 map形式
Click to show internal directories.
Click to hide internal directories.