Documentation
¶
Index ¶
- Variables
- func HasRegister(name MODE) bool
- func Register(name MODE, adapter Instance)
- type AddedFunc
- type Cache
- type EvictedFunc
- type Group
- type Instance
- type LFUPlugin
- func (c *LFUPlugin) Get(key interface{}) (interface{}, error)
- func (c *LFUPlugin) GetALL() map[interface{}]interface{}
- func (c *LFUPlugin) GetIFPresent(key interface{}) (interface{}, error)
- func (c *LFUPlugin) HasKey(key interface{}) bool
- func (c *LFUPlugin) Keys() []interface{}
- func (c *LFUPlugin) Len() int
- func (c *LFUPlugin) Purge()
- func (c *LFUPlugin) Remove(key interface{}) bool
- func (c *LFUPlugin) Set(key, value interface{})
- type LRUPlugin
- func (c *LRUPlugin) Get(key interface{}) (interface{}, error)
- func (c *LRUPlugin) GetALL() map[interface{}]interface{}
- func (c *LRUPlugin) GetIFPresent(key interface{}) (interface{}, error)
- func (c *LRUPlugin) HasKey(key interface{}) bool
- func (c *LRUPlugin) Keys() []interface{}
- func (c *LRUPlugin) Len() int
- func (c *LRUPlugin) Purge()
- func (c *LRUPlugin) Remove(key interface{}) bool
- func (c *LRUPlugin) Set(key, value interface{})
- type LoaderFunc
- type MODE
- type Options
- type Setting
- func (cb *Setting) AddedFunc(addedFunc AddedFunc) *Setting
- func (cb *Setting) EvictType(tp MODE) *Setting
- func (cb *Setting) EvictedFunc(evictedFunc EvictedFunc) *Setting
- func (cb *Setting) Expiration(expiration time.Duration) *Setting
- func (cb *Setting) LFU() *Setting
- func (cb *Setting) LRU() *Setting
- func (cb *Setting) LoaderFunc(loaderFunc LoaderFunc) *Setting
- func (cb *Setting) Setting() Cache
Constants ¶
This section is empty.
Variables ¶
var ( ErrCacheSizeZero = fmt.Errorf("Cache: Size <= 0") ErrCacheRegisterAdapterNil = fmt.Errorf("Cache: Register adapter is nil") ErrCacheCanNotFindAdapter = fmt.Errorf("Cache: Can not find adapter: ") ErrCacheUnknownAdapter = fmt.Errorf("Cache: unknown adapter: ") ErrCacheKeyNotFind = fmt.Errorf("Cache: key not find") )
Functions ¶
func HasRegister ¶
Types ¶
type Cache ¶
type Cache interface { Set(interface{}, interface{}) // set数据 Get(interface{}) (interface{}, error) // get数据 GetIFPresent(interface{}) (interface{}, error) // 获取数据,如果数据不存在则通过cacheLoader获取数据,缓存并返回 GetALL() map[interface{}]interface{} // TODO:获得全量数据,业务慎用 Remove(interface{}) bool // 删除key Purge() // 清除 plguin Keys() []interface{} // 获得全部key Len() int // 获得cache大小 HasKey(interface{}) bool // 判断key是否存在 // contains filtered or unexported methods }
func PluginInstance ¶
type EvictedFunc ¶
type EvictedFunc func(interface{}, interface{})
type LFUPlugin ¶
type LFUPlugin struct { Options // contains filtered or unexported fields }
Discards the least frequently used items first.
func (*LFUPlugin) Get ¶
Get a value from cache pool using key if it exists. If it dose not exists key and has LoaderFunc, generate a value using `LoaderFunc` method returns value.
func (*LFUPlugin) GetALL ¶
func (c *LFUPlugin) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*LFUPlugin) GetIFPresent ¶
Get a value from cache pool using key if it exists. If it dose not exists key, returns KeyNotFoundError. And send a request which refresh value for specified key if cache object has LoaderFunc.
func (*LFUPlugin) Keys ¶
func (c *LFUPlugin) Keys() []interface{}
Returns a slice of the keys in the cache.
type LRUPlugin ¶
type LRUPlugin struct { Options // contains filtered or unexported fields }
func (*LRUPlugin) Get ¶
Get a value from cache pool using key if it exists. If it dose not exists key and has LoaderFunc, generate a value using `LoaderFunc` method returns value.
func (*LRUPlugin) GetALL ¶
func (c *LRUPlugin) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*LRUPlugin) GetIFPresent ¶
func (*LRUPlugin) Keys ¶
func (c *LRUPlugin) Keys() []interface{}
Returns a slice of the keys in the cache.
type LoaderFunc ¶
type LoaderFunc func(interface{}) (interface{}, error)
type Setting ¶
type Setting struct {
// contains filtered or unexported fields
}
func (*Setting) EvictedFunc ¶
func (cb *Setting) EvictedFunc(evictedFunc EvictedFunc) *Setting
func (*Setting) LoaderFunc ¶
func (cb *Setting) LoaderFunc(loaderFunc LoaderFunc) *Setting