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

34 lines
666 B

2 years ago
package gocache
import (
"github.com/allegro/bigcache/v3"
)
// BigCache https://github.com/allegro/bigcache
type BigCache struct {
db *Big // 驱动
GetterInterface GttInterfaceFunc // 不存在的操作
}
2 years ago
// NewCache 实例化组件
2 years ago
func (c *Big) NewCache() *BigCache {
return &BigCache{db: c}
2 years ago
}
2 years ago
// GetInterface 缓存操作
2 years ago
func (gc *BigCache) GetInterface(key string) (ret interface{}) {
f := func() interface{} {
return gc.GetterInterface()
}
2 years ago
// 如果不存在则调用GetterInterface
2 years ago
ret, err := gc.db.Get(key)
if err == bigcache.ErrEntryNotFound {
_ = gc.db.Set(key, f())
ret, _ = gc.db.Get(key)
}
return
}