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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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