Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultCacheType set default cache type for NewDefaultCache function DefaultCacheType = LRUCache )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Put puts an item into cache. Put(key uint64, value interface{}) // Get retrives an item from cache. Get(key uint64) (interface{}, bool) // Peek reads an item from cache. The action is no considered 'Use'. Peek(key uint64) (interface{}, bool) // Remove eliminates an item from cache. Remove(key uint64) // Elems return all items in cache. Elems() []*Item // Len returns current cache size Len() int }
Cache is an interface for cache system
func NewDefaultCache ¶
NewDefaultCache create Cache instance by default cache type
type FIFO ¶
FIFO is 'First-In-First-Out' cache.
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU is 'Least-Recently-Used' cache.
type TTL ¶
TTL is a cache that assigns TTL(Time-To-Live) for each items.
func (*TTL) PutWithTTL ¶
PutWithTTL puts an item into cache with specified TTL.
type TTLUint64 ¶
type TTLUint64 struct {
*TTL
}
TTLUint64 is simple TTL saves only uint64s.
type TwoQueue ¶
type TwoQueue struct {
// contains filtered or unexported fields
}
TwoQueue is a fixed size 2Q cache. 2Q is an enhancement over the standard LRU cache in that it tracks both frequently and recently used entries separately. This avoids a burst in access to new entries from evicting frequently used entries. It adds some additional tracking overhead to the standard LRU cache, and is computationally about 2x the cost, and adds some metadata over head. The ARCCache is similar, but does not require setting any parameters. TwoQueue implementation is based on https://github.com/hashicorp/golang-lru/blob/master/2q.go