Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(args ...interface{})
- func Search(n int, f func(int) bool) int
- func SearchFrom(to int, from int, f func(int) bool) int
- func SliceInsert(s []interface{}, i int, e interface{}) []interface{}
- func SliceInsert2(s []interface{}, i int, e interface{}) []interface{}
- func SliceInsert3(s []interface{}, i int, e interface{}) []interface{}
- func SliceInsert4(s []interface{}, i int, e interface{}) []interface{}
- 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) Has(key interface{}) bool
- func (c *ARC) Keys(checkExpired bool) []interface{}
- func (c *ARC) Len(checkExpired bool) int
- 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 Cache
- type CacheBuilder
- func (cb *CacheBuilder) ARC() *CacheBuilder
- func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
- func (cb *CacheBuilder) Build() Cache
- func (cb *CacheBuilder) BuildOrderedCache() OrderedCache
- 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) ExpiredFunc(expiredFunction ExpiredFunction) *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) PurgeVisitorFunc(purgeVisitorFunc PurgeVisitorFunc) *CacheBuilder
- func (cb *CacheBuilder) SearchCompareFunction(searchFunction SearchCompareFunction) *CacheBuilder
- func (cb *CacheBuilder) SerializeFunc(serializeFunc SerializeFunc) *CacheBuilder
- func (cb *CacheBuilder) Simple() *CacheBuilder
- func (cb *CacheBuilder) SortKeysFunc(sortKeysFunction SortKeysFunction) *CacheBuilder
- type Clock
- type DeserializeFunc
- type EvictedFunc
- type ExpiredFunction
- 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) Has(key interface{}) bool
- func (c *LFUCache) Keys(checkExpired bool) []interface{}
- func (c *LFUCache) Len(checkExpired bool) 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(checkExpired bool) map[interface{}]interface{}
- func (c *LRUCache) GetIFPresent(key interface{}) (interface{}, error)
- func (c *LRUCache) Has(key interface{}) bool
- func (c *LRUCache) Keys(checkExpired bool) []interface{}
- func (c *LRUCache) Len(checkExpired bool) 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 OrderedCache
- type PurgeVisitorFunc
- type RealClock
- type SearchCompareFunction
- 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) Has(key interface{}) bool
- func (c *SimpleCache) Keys(checkExpired bool) []interface{}
- func (c *SimpleCache) Len(checkExpired bool) 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
- type SimpleOrderedCache
- func (c *SimpleOrderedCache) DeQueue() (key interface{}, value interface{}, err error)
- func (c *SimpleOrderedCache) DeQueueBatch(count int) (keys []interface{}, values []interface{}, err error)
- func (c *SimpleOrderedCache) EnQueue(key interface{}, value interface{}) error
- func (c *SimpleOrderedCache) EnQueueBatch(keys []interface{}, values []interface{}) error
- func (c *SimpleOrderedCache) Get(key interface{}) (interface{}, error)
- func (c *SimpleOrderedCache) GetALL() map[interface{}]interface{}
- func (c *SimpleOrderedCache) GetIFPresent(key interface{}) (interface{}, error)
- func (c *SimpleOrderedCache) GetKeysAndValues() (keys []interface{}, values []interface{})
- func (c *SimpleOrderedCache) GetTop() (key interface{}, value interface{}, err error)
- func (c *SimpleOrderedCache) Keys() []interface{}
- func (c *SimpleOrderedCache) Len() int
- func (c *SimpleOrderedCache) MoveFront(key interface{}) error
- func (c *SimpleOrderedCache) OrderedKeys() []interface{}
- func (c *SimpleOrderedCache) Prepend(key interface{}, value interface{}) error
- func (c *SimpleOrderedCache) PrependBatch(keys []interface{}, values []interface{}) error
- func (c *SimpleOrderedCache) PrintValues(stamp int)
- func (c *SimpleOrderedCache) Purge()
- func (c *SimpleOrderedCache) Refresh()
- func (c *SimpleOrderedCache) Remove(key interface{}) bool
- func (c *SimpleOrderedCache) RemoveExpired(allowFailCount int) error
- func (c *SimpleOrderedCache) Sort()
- type SortKeysFunction
Constants ¶
const ( TYPE_SIMPLE = "simple" TYPE_LRU = "lru" TYPE_LFU = "lfu" TYPE_ARC = "arc" )
Variables ¶
var DebugMode bool
var EmptyErr = errors.New("cache is empty")
var KeyNotFoundError = errors.New("Key not found.")
var ReachedMaxSizeErr = errors.New("reached max size")
Functions ¶
func SliceInsert ¶
func SliceInsert(s []interface{}, i int, e interface{}) []interface{}
this is fastest one
func SliceInsert2 ¶
func SliceInsert2(s []interface{}, i int, e interface{}) []interface{}
func SliceInsert3 ¶
func SliceInsert3(s []interface{}, i int, e interface{}) []interface{}
func SliceInsert4 ¶
func SliceInsert4(s []interface{}, i int, e interface{}) []interface{}
Types ¶
type ARC ¶
type ARC struct {
// 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.
type Cache ¶
type Cache interface { Set(key, value interface{}) error SetWithExpire(key, value interface{}, expiration time.Duration) error Get(key interface{}) (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 CacheBuilder ¶
type CacheBuilder struct {
// contains filtered or unexported fields
}
func New ¶
func New(size int) *CacheBuilder
func (*CacheBuilder) ARC ¶
func (cb *CacheBuilder) ARC() *CacheBuilder
func (*CacheBuilder) AddedFunc ¶
func (cb *CacheBuilder) AddedFunc(addedFunc AddedFunc) *CacheBuilder
func (*CacheBuilder) Build ¶
func (cb *CacheBuilder) Build() Cache
func (*CacheBuilder) BuildOrderedCache ¶
func (cb *CacheBuilder) BuildOrderedCache() OrderedCache
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) ExpiredFunc ¶ added in v0.0.2
func (cb *CacheBuilder) ExpiredFunc(expiredFunction ExpiredFunction) *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. 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 (*CacheBuilder) LoaderFunc ¶
func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder
Set a loader function. loaderFunc: create a new value with this function if cached value is expired.
func (*CacheBuilder) PurgeVisitorFunc ¶
func (cb *CacheBuilder) PurgeVisitorFunc(purgeVisitorFunc PurgeVisitorFunc) *CacheBuilder
func (*CacheBuilder) SearchCompareFunction ¶
func (cb *CacheBuilder) SearchCompareFunction(searchFunction SearchCompareFunction) *CacheBuilder
func (*CacheBuilder) SerializeFunc ¶
func (cb *CacheBuilder) SerializeFunc(serializeFunc SerializeFunc) *CacheBuilder
func (*CacheBuilder) Simple ¶
func (cb *CacheBuilder) Simple() *CacheBuilder
func (*CacheBuilder) SortKeysFunc ¶
func (cb *CacheBuilder) SortKeysFunc(sortKeysFunction SortKeysFunction) *CacheBuilder
type DeserializeFunc ¶
type DeserializeFunc func(interface{}, interface{}) (interface{}, error)
type EvictedFunc ¶
type EvictedFunc func(interface{}, interface{})
type ExpiredFunction ¶
type ExpiredFunction func(interface{}) bool
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 {
// 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.
type LRUCache ¶
type LRUCache struct {
// 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.
type LoaderExpireFunc ¶
type LoaderFunc ¶
type LoaderFunc func(interface{}) (interface{}, error)
type OrderedCache ¶
type OrderedCache interface { //for ordered (queues) cache, EnQueue(interface{}, interface{}) error EnQueueBatch([]interface{}, []interface{}) error //EnQueueBatch if searchFunc is not nil , keys are required sorted DeQueue() (interface{}, interface{}, error) DeQueueBatch(count int) ([]interface{}, []interface{}, error) OrderedKeys() []interface{} MoveFront(interface{}) error //move an element to front GetTop() (interface{}, interface{}, error) //get top element Prepend(interface{}, interface{}) error PrependBatch([]interface{}, []interface{}) error //PrependBatch if searchFunc is not nil , keys are required sorted RemoveExpired(allowFailCount int) error Get(interface{}) (interface{}, error) GetIFPresent(interface{}) (interface{}, error) GetALL() map[interface{}]interface{} GetKeysAndValues() ([]interface{}, []interface{}) Remove(interface{}) bool PrintValues(int) Purge() Refresh() Keys() []interface{} Len() int Sort() // contains filtered or unexported methods }
type PurgeVisitorFunc ¶
type PurgeVisitorFunc func(interface{}, interface{})
type SearchCompareFunction ¶
type SearchCompareFunction func(value interface{}, anotherValue interface{}) int
type SerializeFunc ¶
type SerializeFunc func(interface{}, interface{}) (interface{}, error)
type SimpleCache ¶
type SimpleCache struct {
// 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) Has ¶
func (c *SimpleCache) Has(key interface{}) bool
Has checks if key exists in cache
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) 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
type SimpleOrderedCache ¶
type SimpleOrderedCache struct {
// contains filtered or unexported fields
}
SimpleOrderedCache has no clear priority for evict cache. It depends on key-value map order.
func (*SimpleOrderedCache) DeQueue ¶
func (c *SimpleOrderedCache) DeQueue() (key interface{}, value interface{}, err error)
func (*SimpleOrderedCache) DeQueueBatch ¶
func (c *SimpleOrderedCache) DeQueueBatch(count int) (keys []interface{}, values []interface{}, err error)
func (*SimpleOrderedCache) EnQueue ¶
func (c *SimpleOrderedCache) EnQueue(key interface{}, value interface{}) error
func (*SimpleOrderedCache) EnQueueBatch ¶
func (c *SimpleOrderedCache) EnQueueBatch(keys []interface{}, values []interface{}) error
EnQueueBatch if searchCmpFunc is not nil , keys are required sorted
func (*SimpleOrderedCache) Get ¶
func (c *SimpleOrderedCache) 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 (*SimpleOrderedCache) GetALL ¶
func (c *SimpleOrderedCache) GetALL() map[interface{}]interface{}
Returns all key-value pairs in the cache.
func (*SimpleOrderedCache) GetIFPresent ¶
func (c *SimpleOrderedCache) 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 (*SimpleOrderedCache) GetKeysAndValues ¶
func (c *SimpleOrderedCache) GetKeysAndValues() (keys []interface{}, values []interface{})
func (*SimpleOrderedCache) GetTop ¶
func (c *SimpleOrderedCache) GetTop() (key interface{}, value interface{}, err error)
func (*SimpleOrderedCache) Keys ¶
func (c *SimpleOrderedCache) Keys() []interface{}
Returns a slice of the keys in the cache.
func (*SimpleOrderedCache) Len ¶
func (c *SimpleOrderedCache) Len() int
Returns the number of items in the cache.
func (*SimpleOrderedCache) MoveFront ¶
func (c *SimpleOrderedCache) MoveFront(key interface{}) error
func (*SimpleOrderedCache) OrderedKeys ¶
func (c *SimpleOrderedCache) OrderedKeys() []interface{}
func (*SimpleOrderedCache) Prepend ¶
func (c *SimpleOrderedCache) Prepend(key interface{}, value interface{}) error
func (*SimpleOrderedCache) PrependBatch ¶
func (c *SimpleOrderedCache) PrependBatch(keys []interface{}, values []interface{}) error
func (*SimpleOrderedCache) PrintValues ¶
func (c *SimpleOrderedCache) PrintValues(stamp int)
for test
func (*SimpleOrderedCache) Refresh ¶
func (c *SimpleOrderedCache) Refresh()
func (*SimpleOrderedCache) Remove ¶
func (c *SimpleOrderedCache) Remove(key interface{}) bool
Removes the provided key from the cache.
func (*SimpleOrderedCache) RemoveExpired ¶
func (c *SimpleOrderedCache) RemoveExpired(allowFailCount int) error
func (*SimpleOrderedCache) Sort ¶
func (c *SimpleOrderedCache) Sort()