Documentation ¶
Index ¶
- Constants
- Variables
- type ARC
- func (c *ARC) Get(key interface{}) (interface{}, error)
- func (c *ARC) GetAll(checkExpired bool) map[interface{}]interface{}
- func (c *ARC) GetIfPresent(key interface{}) (interface{}, error)
- func (c *ARC) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
- func (c *ARC) Has(key interface{}) bool
- func (st ARC) HitCount() uint64
- func (st ARC) HitRate() float64
- func (st ARC) IncrHitCount() uint64
- func (st ARC) IncrMissCount() uint64
- func (c *ARC) Keys(checkExpired bool) []interface{}
- func (c *ARC) Len(checkExpired bool) int
- func (st ARC) LookupCount() uint64
- func (st ARC) MissCount() uint64
- func (c *ARC) Purge()
- func (c *ARC) Remove(key interface{}) bool
- func (c *ARC) Set(key, value interface{}) error
- func (c *ARC) SetWithExpire(key, value interface{}, expiration time.Duration) error
- type AddedFunc
- type BaseCache
- type Builder
- func (b *Builder) ARC() *Builder
- func (b *Builder) AddedFunc(addedFunc AddedFunc) *Builder
- func (b *Builder) Build() Cache
- func (b *Builder) Clock(clock Clock) *Builder
- func (b *Builder) DeserializeFunc(deserializeFunc DeserializeFunc) *Builder
- func (b *Builder) EvictType(tp string) *Builder
- func (b *Builder) EvictedFunc(evictedFunc EvictedFunc) *Builder
- func (b *Builder) Expiration(expiration time.Duration) *Builder
- func (b *Builder) LFU() *Builder
- func (b *Builder) LRU() *Builder
- func (b *Builder) LoaderExpireFunc(loaderExpireFunc LoaderExpireFunc) *Builder
- func (b *Builder) LoaderFunc(loaderFunc LoaderFunc) *Builder
- func (b *Builder) PurgeVisitorFunc(purgeVisitorFunc PurgeVisitorFunc) *Builder
- func (b *Builder) SerializeFunc(serializeFunc SerializeFunc) *Builder
- func (b *Builder) Simple() *Builder
- type Cache
- type Clock
- type DeserializeFunc
- type EvictedFunc
- type Expirable
- type FakeClock
- type Group
- type LFUCache
- func (c *LFUCache) Get(key interface{}) (interface{}, error)
- func (c *LFUCache) GetAll(checkExpired bool) map[interface{}]interface{}
- func (c *LFUCache) GetIfPresent(key interface{}) (interface{}, error)
- func (c *LFUCache) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
- func (c *LFUCache) Has(key interface{}) bool
- func (st LFUCache) HitCount() uint64
- func (st LFUCache) HitRate() float64
- func (st LFUCache) IncrHitCount() uint64
- func (st LFUCache) IncrMissCount() uint64
- func (c *LFUCache) Keys(checkExpired bool) []interface{}
- func (c *LFUCache) Len(checkExpired bool) int
- func (st LFUCache) LookupCount() uint64
- func (st LFUCache) MissCount() uint64
- 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(checkExpired bool) map[interface{}]interface{}
- func (c *LRUCache) GetIfPresent(key interface{}) (interface{}, error)
- func (c *LRUCache) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
- func (c *LRUCache) Has(key interface{}) bool
- func (st LRUCache) HitCount() uint64
- func (st LRUCache) HitRate() float64
- func (st LRUCache) IncrHitCount() uint64
- func (st LRUCache) IncrMissCount() uint64
- func (c *LRUCache) Keys(checkExpired bool) []interface{}
- func (c *LRUCache) Len(checkExpired bool) int
- func (st LRUCache) LookupCount() uint64
- func (st LRUCache) MissCount() uint64
- 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 PurgeVisitorFunc
- type RealClock
- type SerializeFunc
- type SimpleCache
- func (c *SimpleCache) Get(key interface{}) (interface{}, error)
- func (c *SimpleCache) GetAll(checkExpired bool) map[interface{}]interface{}
- func (c *SimpleCache) GetIfPresent(key interface{}) (interface{}, error)
- func (c *SimpleCache) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
- func (c *SimpleCache) Has(key interface{}) bool
- func (st SimpleCache) HitCount() uint64
- func (st SimpleCache) HitRate() float64
- func (st SimpleCache) IncrHitCount() uint64
- func (st SimpleCache) IncrMissCount() uint64
- func (c *SimpleCache) Keys(checkExpired bool) []interface{}
- func (c *SimpleCache) Len(checkExpired bool) int
- func (st SimpleCache) LookupCount() uint64
- func (st SimpleCache) MissCount() uint64
- 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 ( TypeSimple = "simple" TypeLru = "lru" TypeLfu = "lfu" TypeArc = "arc" )
Variables ¶
var KeyNotFoundError = errors.New("key not found")
var NoExpiration *time.Duration = nil
Functions ¶
This section is empty.
Types ¶
type ARC ¶
type ARC struct { BaseCache // contains filtered or unexported fields }
Constantly balances between LRU and LFU, to improve the combined result.
func (*ARC) Get ¶
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 (*ARC) GetIfPresent ¶
GetIfPresent gets 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 (*ARC) GetOrLoad ¶
func (c *ARC) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
Get a value from cache pool using key if it exists. If not exists, it will generate the value using given specified LoaderFunc method returns value.
func (ARC) HitRate ¶ added in v0.2.0
func (st ARC) HitRate() float64
HitRate returns rate for cache hitting
func (ARC) IncrMissCount ¶ added in v0.2.0
func (st ARC) IncrMissCount() uint64
increment miss count
func (ARC) LookupCount ¶ added in v0.2.0
func (st ARC) LookupCount() uint64
LookupCount returns lookup count
func (ARC) MissCount ¶ added in v0.2.0
func (st ARC) MissCount() uint64
MissCount returns miss count
type BaseCache ¶ added in v0.2.0
type BaseCache struct {
// contains filtered or unexported fields
}
func (BaseCache) HitCount ¶ added in v0.2.0
func (st BaseCache) HitCount() uint64
HitCount returns hit count
func (BaseCache) HitRate ¶ added in v0.2.0
func (st BaseCache) HitRate() float64
HitRate returns rate for cache hitting
func (BaseCache) IncrHitCount ¶ added in v0.2.0
func (st BaseCache) IncrHitCount() uint64
increment hit count
func (BaseCache) IncrMissCount ¶ added in v0.2.0
func (st BaseCache) IncrMissCount() uint64
increment miss count
func (BaseCache) LookupCount ¶ added in v0.2.0
func (st BaseCache) LookupCount() uint64
LookupCount returns lookup count
type Builder ¶ added in v0.2.0
type Builder struct {
// contains filtered or unexported fields
}
func NewWithEvictType ¶ added in v0.2.0
func (*Builder) DeserializeFunc ¶ added in v0.2.0
func (b *Builder) DeserializeFunc(deserializeFunc DeserializeFunc) *Builder
func (*Builder) EvictedFunc ¶ added in v0.2.0
func (b *Builder) EvictedFunc(evictedFunc EvictedFunc) *Builder
func (*Builder) Expiration ¶ added in v0.2.0
func (*Builder) LoaderExpireFunc ¶ added in v0.2.0
func (b *Builder) LoaderExpireFunc(loaderExpireFunc LoaderExpireFunc) *Builder
Set a loader function with expiration. loaderExpireFunc: create a new value with this function if cached value is expired. If nil returned instead of time.Duration from loaderExpireFunc than value will never expire.
func (*Builder) LoaderFunc ¶ added in v0.2.0
func (b *Builder) LoaderFunc(loaderFunc LoaderFunc) *Builder
Set a loader function. loaderFunc: create a new value with this function if cached value is expired.
func (*Builder) PurgeVisitorFunc ¶ added in v0.2.0
func (b *Builder) PurgeVisitorFunc(purgeVisitorFunc PurgeVisitorFunc) *Builder
func (*Builder) SerializeFunc ¶ added in v0.2.0
func (b *Builder) SerializeFunc(serializeFunc SerializeFunc) *Builder
type Cache ¶
type Cache interface { Set(key, value interface{}) error SetWithExpire(key, value interface{}, expiration time.Duration) error Get(key interface{}) (interface{}, error) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error) GetIfPresent(key interface{}) (interface{}, error) GetAll(checkExpired bool) map[interface{}]interface{} Remove(key interface{}) bool Purge() Keys(checkExpired bool) []interface{} Len(checkExpired bool) int Has(key interface{}) bool // contains filtered or unexported methods }
type DeserializeFunc ¶
type DeserializeFunc func(interface{}, interface{}) (interface{}, error)
type EvictedFunc ¶
type EvictedFunc func(interface{}, interface{})
type Expirable ¶ added in v0.3.0
type Expirable struct { Value interface{} // Value Expire time.Duration // Specified expiration of this value; expire<=0 will use default }
func NewDefault ¶ added in v0.3.0
func NewDefault(value interface{}) Expirable
func NewExpirable ¶ added in v0.3.0
type FakeClock ¶
func NewFakeClock ¶
func NewFakeClock() FakeClock
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.
func (*Group) Do ¶
func (g *Group) Do(key interface{}, fn func() (interface{}, error), isWait bool) (interface{}, bool, error)
Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.
type LFUCache ¶
type LFUCache struct { BaseCache // contains filtered or unexported fields }
Discards the least frequently used items first.
func (*LFUCache) 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 (*LFUCache) GetIfPresent ¶
GetIfPresent gets 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 (*LFUCache) GetOrLoad ¶
func (c *LFUCache) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
Get a value from cache pool using key if it exists. If it dose not exists key, generate a value using `LoaderFunc` method returns value.
func (LFUCache) HitCount ¶ added in v0.2.0
func (st LFUCache) HitCount() uint64
HitCount returns hit count
func (LFUCache) HitRate ¶ added in v0.2.0
func (st LFUCache) HitRate() float64
HitRate returns rate for cache hitting
func (LFUCache) IncrHitCount ¶ added in v0.2.0
func (st LFUCache) IncrHitCount() uint64
increment hit count
func (LFUCache) IncrMissCount ¶ added in v0.2.0
func (st LFUCache) IncrMissCount() uint64
increment miss count
func (LFUCache) LookupCount ¶ added in v0.2.0
func (st LFUCache) LookupCount() uint64
LookupCount returns lookup count
func (LFUCache) MissCount ¶ added in v0.2.0
func (st LFUCache) MissCount() uint64
MissCount returns miss count
type LRUCache ¶
type LRUCache struct { BaseCache // contains filtered or unexported fields }
Discards the least recently used items first.
func (*LRUCache) 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 (*LRUCache) GetIfPresent ¶
GetIfPresent gets 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 (*LRUCache) GetOrLoad ¶
func (c *LRUCache) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
Get a value from cache pool using key if it exists. If it dose not exists key, generate a value using `LoaderFunc` method returns value.
func (LRUCache) HitCount ¶ added in v0.2.0
func (st LRUCache) HitCount() uint64
HitCount returns hit count
func (LRUCache) HitRate ¶ added in v0.2.0
func (st LRUCache) HitRate() float64
HitRate returns rate for cache hitting
func (LRUCache) IncrHitCount ¶ added in v0.2.0
func (st LRUCache) IncrHitCount() uint64
increment hit count
func (LRUCache) IncrMissCount ¶ added in v0.2.0
func (st LRUCache) IncrMissCount() uint64
increment miss count
func (LRUCache) LookupCount ¶ added in v0.2.0
func (st LRUCache) LookupCount() uint64
LookupCount returns lookup count
func (LRUCache) MissCount ¶ added in v0.2.0
func (st LRUCache) MissCount() uint64
MissCount returns miss count
type LoaderExpireFunc ¶
type LoaderFunc ¶
type LoaderFunc func(interface{}) (interface{}, error)
type PurgeVisitorFunc ¶
type PurgeVisitorFunc func(interface{}, interface{})
type SerializeFunc ¶
type SerializeFunc func(interface{}, interface{}) (interface{}, error)
type SimpleCache ¶
type SimpleCache struct { BaseCache // contains filtered or unexported fields }
SimpleCache has no clear priority for evict cache. It depends on key-value map order.
func (*SimpleCache) Get ¶
func (c *SimpleCache) 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 (*SimpleCache) GetAll ¶
func (c *SimpleCache) GetAll(checkExpired bool) map[interface{}]interface{}
GetAll returns all key-value pairs in the cache.
func (*SimpleCache) GetIfPresent ¶
func (c *SimpleCache) GetIfPresent(key interface{}) (interface{}, error)
GetIfPresent gets 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 (*SimpleCache) GetOrLoad ¶
func (c *SimpleCache) GetOrLoad(key interface{}, loader LoaderExpireFunc) (interface{}, error)
Get a value from cache pool using key if it exists. If it dose not exists key, generate a value using `LoaderFunc` method returns value.
func (*SimpleCache) Has ¶
func (c *SimpleCache) Has(key interface{}) bool
Has checks if key exists in cache
func (SimpleCache) HitCount ¶ added in v0.2.0
func (st SimpleCache) HitCount() uint64
HitCount returns hit count
func (SimpleCache) HitRate ¶ added in v0.2.0
func (st SimpleCache) HitRate() float64
HitRate returns rate for cache hitting
func (SimpleCache) IncrHitCount ¶ added in v0.2.0
func (st SimpleCache) IncrHitCount() uint64
increment hit count
func (SimpleCache) IncrMissCount ¶ added in v0.2.0
func (st SimpleCache) IncrMissCount() uint64
increment miss count
func (*SimpleCache) Keys ¶
func (c *SimpleCache) Keys(checkExpired bool) []interface{}
Keys returns a slice of the keys in the cache.
func (*SimpleCache) Len ¶
func (c *SimpleCache) Len(checkExpired bool) int
Len returns the number of items in the cache.
func (SimpleCache) LookupCount ¶ added in v0.2.0
func (st SimpleCache) LookupCount() uint64
LookupCount returns lookup count
func (SimpleCache) MissCount ¶ added in v0.2.0
func (st SimpleCache) MissCount() uint64
MissCount returns miss count
func (*SimpleCache) Remove ¶
func (c *SimpleCache) Remove(key interface{}) bool
Remove 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