Documentation ¶
Index ¶
- Variables
- func HasRegister(name MODE) bool
- func Register(name MODE, adapter Instance)
- type ARCPlugin
- func (c *ARCPlugin) Get(key interface{}) (interface{}, error)
- func (c *ARCPlugin) GetALL() map[interface{}]interface{}
- func (c *ARCPlugin) GetIFPresent(key interface{}) (interface{}, error)
- func (c *ARCPlugin) HasKey(key interface{}) bool
- func (c *ARCPlugin) Keys() []interface{}
- func (c *ARCPlugin) Len() int
- func (c *ARCPlugin) Purge()
- func (c *ARCPlugin) Remove(key interface{}) bool
- func (c *ARCPlugin) Set(key, value interface{})
- type AddedFunc
- type Cache
- type EvictedFunc
- type FIFOPlugin
- func (c *FIFOPlugin) Get(key interface{}) (interface{}, error)
- func (c *FIFOPlugin) GetALL() map[interface{}]interface{}
- func (c *FIFOPlugin) GetIFPresent(key interface{}) (interface{}, error)
- func (c *FIFOPlugin) HasKey(key interface{}) bool
- func (c *FIFOPlugin) Keys() []interface{}
- func (c *FIFOPlugin) Len() int
- func (c *FIFOPlugin) Purge()
- func (c *FIFOPlugin) Remove(key interface{}) bool
- func (c *FIFOPlugin) Set(key, value interface{})
- 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) ARC() *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) FIFO() *Setting
- func (cb *Setting) LFU() *Setting
- func (cb *Setting) LRU() *Setting
- func (cb *Setting) LoaderFunc(loaderFunc LoaderFunc) *Setting
- func (cb *Setting) Setting() Cache
- func (cb *Setting) Simple() *Setting
- type SimplePlugin
- func (c *SimplePlugin) Get(key interface{}) (interface{}, error)
- func (c *SimplePlugin) GetALL() map[interface{}]interface{}
- func (c *SimplePlugin) GetIFPresent(key interface{}) (interface{}, error)
- func (c *SimplePlugin) HasKey(key interface{}) bool
- func (c *SimplePlugin) Keys() []interface{}
- func (c *SimplePlugin) Len() int
- func (c *SimplePlugin) Purge()
- func (c *SimplePlugin) Remove(key interface{}) bool
- func (c *SimplePlugin) Set(key, value interface{})
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 ARCPlugin ¶ added in v1.0.2
type ARCPlugin struct { Options // contains filtered or unexported fields }
func (*ARCPlugin) Get ¶ added in v1.0.2
Get a value from cache pool using key if it exists. If not exists and it has LoaderFunc, it will generate the value using you have specified LoaderFunc method returns value.
func (*ARCPlugin) GetALL ¶ added in v1.0.2
func (c *ARCPlugin) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*ARCPlugin) GetIFPresent ¶ added in v1.0.2
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 (*ARCPlugin) Keys ¶ added in v1.0.2
func (c *ARCPlugin) Keys() []interface{}
Keys returns a slice of the keys in the cache.
func (*ARCPlugin) Purge ¶ added in v1.0.2
func (c *ARCPlugin) Purge()
Purge is used to completely clear the cache
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 NewARCPlugin ¶ added in v1.0.2
NewARCPlugin returns a new plugin.
func NewFIFOPlugin ¶ added in v1.1.1
NewFIFOPlugin returns a new plugin.
func NewSimplePlugin ¶ added in v1.0.2
func PluginInstance ¶
type EvictedFunc ¶
type EvictedFunc func(interface{}, interface{})
type FIFOPlugin ¶ added in v1.1.1
type FIFOPlugin struct { Options // contains filtered or unexported fields }
func (*FIFOPlugin) Get ¶ added in v1.1.1
func (c *FIFOPlugin) Get(key interface{}) (interface{}, error)
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 (*FIFOPlugin) GetALL ¶ added in v1.1.1
func (c *FIFOPlugin) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*FIFOPlugin) GetIFPresent ¶ added in v1.1.1
func (c *FIFOPlugin) GetIFPresent(key interface{}) (interface{}, error)
func (*FIFOPlugin) HasKey ¶ added in v1.1.1
func (c *FIFOPlugin) HasKey(key interface{}) bool
func (*FIFOPlugin) Keys ¶ added in v1.1.1
func (c *FIFOPlugin) Keys() []interface{}
Returns a slice of the keys in the cache.
func (*FIFOPlugin) Len ¶ added in v1.1.1
func (c *FIFOPlugin) Len() int
Returns the number of items in the cache.
func (*FIFOPlugin) Remove ¶ added in v1.1.1
func (c *FIFOPlugin) Remove(key interface{}) bool
Removes the provided key from the cache.
func (*FIFOPlugin) Set ¶ added in v1.1.1
func (c *FIFOPlugin) Set(key, value interface{})
set a new key-value pair
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
type SimplePlugin ¶ added in v1.0.2
type SimplePlugin struct { Options // contains filtered or unexported fields }
SimplePlugin has no clear priority for evict cache. It depends on key-value map order.
func (*SimplePlugin) Get ¶ added in v1.0.2
func (c *SimplePlugin) Get(key interface{}) (interface{}, error)
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 (*SimplePlugin) GetALL ¶ added in v1.0.2
func (c *SimplePlugin) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*SimplePlugin) GetIFPresent ¶ added in v1.0.2
func (c *SimplePlugin) GetIFPresent(key interface{}) (interface{}, error)
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 (*SimplePlugin) HasKey ¶ added in v1.0.2
func (c *SimplePlugin) HasKey(key interface{}) bool
func (*SimplePlugin) Keys ¶ added in v1.0.2
func (c *SimplePlugin) Keys() []interface{}
Returns a slice of the keys in the cache.
func (*SimplePlugin) Len ¶ added in v1.0.2
func (c *SimplePlugin) Len() int
Returns the number of items in the cache.
func (*SimplePlugin) Purge ¶ added in v1.0.2
func (c *SimplePlugin) Purge()
Completely clear the cache
func (*SimplePlugin) Remove ¶ added in v1.0.2
func (c *SimplePlugin) Remove(key interface{}) bool
Removes the provided key from the cache.
func (*SimplePlugin) Set ¶ added in v1.0.2
func (c *SimplePlugin) Set(key, value interface{})
set a new key-value pair