Documentation ¶
Index ¶
- Constants
- Variables
- type AddedFunc
- type Cache
- type CacheBuilder
- func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
- func (cb *CacheBuilder) Build() Cache
- func (cb *CacheBuilder) Clock(clock Clock) *CacheBuilder
- func (cb *CacheBuilder) DeserializeFunc(deserializeFunc DeserializeFunc) *CacheBuilder
- func (cb *CacheBuilder) EvictType(tp string) *CacheBuilder
- func (cb *CacheBuilder) EvictedFunc(evictedFunc EvictedFunc) *CacheBuilder
- func (cb *CacheBuilder) Expiration(expiration time.Duration) *CacheBuilder
- func (cb *CacheBuilder) LFU() *CacheBuilder
- func (cb *CacheBuilder) LRU() *CacheBuilder
- func (cb *CacheBuilder) LoaderExpireFunc(loaderExpireFunc LoaderExpireFunc) *CacheBuilder
- func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder
- func (cb *CacheBuilder) SerializeFunc(serializeFunc SerializeFunc) *CacheBuilder
- func (cb *CacheBuilder) Simple() *CacheBuilder
- type Clock
- type DeserializeFunc
- type EvictedFunc
- type Group
- type LFUCache
- func (c *LFUCache) Get(key interface{}) (interface{}, error)
- func (c *LFUCache) GetALL() map[interface{}]interface{}
- func (c *LFUCache) GetIFPresent(key interface{}) (interface{}, error)
- func (c *LFUCache) Keys() []interface{}
- func (c *LFUCache) Len() int
- func (c *LFUCache) Purge()
- func (c *LFUCache) Remove(key interface{}) bool
- func (c *LFUCache) Set(key, value interface{}) error
- func (c *LFUCache) SetWithExpire(key, value interface{}, expiration time.Duration) error
- type LRUCache
- func (c *LRUCache) Get(key interface{}) (interface{}, error)
- func (c *LRUCache) GetALL() map[interface{}]interface{}
- func (c *LRUCache) GetIFPresent(key interface{}) (interface{}, error)
- func (c *LRUCache) Keys() []interface{}
- func (c *LRUCache) Len() int
- func (c *LRUCache) Purge()
- func (c *LRUCache) Remove(key interface{}) bool
- func (c *LRUCache) Set(key, value interface{}) error
- func (c *LRUCache) SetWithExpire(key, value interface{}, expiration time.Duration) error
- type LoaderExpireFunc
- type LoaderFunc
- type RealClock
- type SerializeFunc
- type SimpleCache
- func (c *SimpleCache) Get(key interface{}) (interface{}, error)
- func (c *SimpleCache) GetALL() map[interface{}]interface{}
- func (c *SimpleCache) GetIFPresent(key interface{}) (interface{}, error)
- func (c *SimpleCache) Keys() []interface{}
- func (c *SimpleCache) Len() int
- func (c *SimpleCache) Purge()
- func (c *SimpleCache) Remove(key interface{}) bool
- func (c *SimpleCache) Set(key, value interface{}) error
- func (c *SimpleCache) SetWithExpire(key, value interface{}, expiration time.Duration) error
Constants ¶
const ( TYPE_SIMPLE = "simple" TYPE_LRU = "lru" TYPE_LFU = "lfu" )
Variables ¶
var KeyNotFoundError = errors.New("Key not found.")
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { Set(interface{}, interface{}) error SetWithExpire(interface{}, interface{}, time.Duration) error Get(interface{}) (interface{}, error) GetIFPresent(interface{}) (interface{}, error) GetALL() map[interface{}]interface{} Remove(interface{}) bool Purge() Keys() []interface{} Len() int // contains filtered or unexported methods }
Cache operations
type CacheBuilder ¶
type CacheBuilder struct {
// contains filtered or unexported fields
}
func New ¶
func New(size int) *CacheBuilder
func (*CacheBuilder) AddedFunc ¶
func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
func (*CacheBuilder) Build ¶
func (cb *CacheBuilder) Build() Cache
func (*CacheBuilder) Clock ¶
func (cb *CacheBuilder) Clock(clock Clock) *CacheBuilder
func (*CacheBuilder) DeserializeFunc ¶
func (cb *CacheBuilder) DeserializeFunc(deserializeFunc DeserializeFunc) *CacheBuilder
func (*CacheBuilder) EvictType ¶
func (cb *CacheBuilder) EvictType(tp string) *CacheBuilder
func (*CacheBuilder) EvictedFunc ¶
func (cb *CacheBuilder) EvictedFunc(evictedFunc EvictedFunc) *CacheBuilder
func (*CacheBuilder) Expiration ¶
func (cb *CacheBuilder) Expiration(expiration time.Duration) *CacheBuilder
func (*CacheBuilder) LFU ¶
func (cb *CacheBuilder) LFU() *CacheBuilder
func (*CacheBuilder) LRU ¶
func (cb *CacheBuilder) LRU() *CacheBuilder
func (*CacheBuilder) LoaderExpireFunc ¶
func (cb *CacheBuilder) LoaderExpireFunc(loaderExpireFunc LoaderExpireFunc) *CacheBuilder
Set a loader function with expiration.
func (*CacheBuilder) LoaderFunc ¶
func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder
LoaderFunc: create a new value with this function if cached value is expired.
func (*CacheBuilder) SerializeFunc ¶
func (cb *CacheBuilder) SerializeFunc(serializeFunc SerializeFunc) *CacheBuilder
func (*CacheBuilder) Simple ¶
func (cb *CacheBuilder) Simple() *CacheBuilder
type DeserializeFunc ¶
type DeserializeFunc func(interface{}, interface{}) (interface{}, error)
type EvictedFunc ¶
type EvictedFunc func(interface{}, interface{})
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a class of work
type LFUCache ¶
type LFUCache struct {
// contains filtered or unexported fields
}
Discards the least frequently used items first.
func (*LFUCache) GetALL ¶
func (c *LFUCache) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*LFUCache) GetIFPresent ¶
Get a value from cache pool using key if it exists.
func (*LFUCache) Keys ¶
func (c *LFUCache) Keys() []interface{}
Returns a slice of the keys in the cache.
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRUCache
func (*LRUCache) GetALL ¶
func (c *LRUCache) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*LRUCache) GetIFPresent ¶
Get a value from cache pool using key if it exists.
func (*LRUCache) Keys ¶
func (c *LRUCache) Keys() []interface{}
Returns a slice of the keys in the cache.
type LoaderExpireFunc ¶
type LoaderFunc ¶
type LoaderFunc func(interface{}) (interface{}, error)
type SerializeFunc ¶
type SerializeFunc func(interface{}, interface{}) (interface{}, error)
type SimpleCache ¶
type SimpleCache struct {
// contains filtered or unexported fields
}
func (*SimpleCache) Get ¶
func (c *SimpleCache) Get(key interface{}) (interface{}, error)
Get a value from cache pool using key if it exists.
func (*SimpleCache) GetALL ¶
func (c *SimpleCache) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*SimpleCache) GetIFPresent ¶
func (c *SimpleCache) GetIFPresent(key interface{}) (interface{}, error)
Get a value from cache pool using key if it exists.
func (*SimpleCache) Keys ¶
func (c *SimpleCache) Keys() []interface{}
Returns a slice of the keys in the cache.
func (*SimpleCache) Remove ¶
func (c *SimpleCache) Remove(key interface{}) bool
Removes the provided key from the cache.
func (*SimpleCache) Set ¶
func (c *SimpleCache) Set(key, value interface{}) error
Set a new key-value pair
func (*SimpleCache) SetWithExpire ¶
func (c *SimpleCache) SetWithExpire(key, value interface{}, expiration time.Duration) error
Set a new key-value pair with an expiration time