Documentation ¶
Index ¶
- type ConcurrentCounterCache
- type EvictCallback
- type LRU
- func (c *LRU) Add(key, value interface{})
- func (c *LRU) AddIfAbsent(key interface{}, value interface{}) (priorValue interface{})
- func (c *LRU) Contains(key interface{}) (ok bool)
- func (c *LRU) Get(key interface{}) (value interface{}, isFound bool)
- func (c *LRU) GetOldest() (key interface{}, value interface{}, ok bool)
- func (c *LRU) Keys() []interface{}
- func (c *LRU) Len() int
- func (c *LRU) Peek(key interface{}) (value interface{}, isFound bool)
- func (c *LRU) Purge()
- func (c *LRU) Remove(key interface{}) (isFound bool)
- func (c *LRU) RemoveOldest() (key interface{}, value interface{}, ok bool)
- func (c *LRU) Resize(size int) (evicted int)
- type LruCacheMap
- func (c *LruCacheMap) Add(key interface{}, value *int64)
- func (c *LruCacheMap) AddIfAbsent(key interface{}, value *int64) (priorValue *int64)
- func (c *LruCacheMap) Contains(key interface{}) (ok bool)
- func (c *LruCacheMap) Get(key interface{}) (value *int64, isFound bool)
- func (c *LruCacheMap) Keys() []interface{}
- func (c *LruCacheMap) Len() int
- func (c *LruCacheMap) Purge()
- func (c *LruCacheMap) Remove(key interface{}) (isFound bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentCounterCache ¶
type ConcurrentCounterCache interface { // Add add a value to the cache, // Updates the "recently used"-ness of the key. Add(key interface{}, value *int64) // If the key is not existed in the cache, adds a value to the cache then return nil. And updates the "recently used"-ness of the key // If the key is already existed in the cache, do nothing and return the prior value AddIfAbsent(key interface{}, value *int64) (priorValue *int64) // Get returns key's value from the cache and updates the "recently used"-ness of the key. Get(key interface{}) (value *int64, isFound bool) // Remove removes a key from the cache. // Return true if the key was contained. Remove(key interface{}) (isFound bool) // Contains checks if a key exists in cache // Without updating the recent-ness. Contains(key interface{}) (ok bool) // Keys returns a slice of the keys in the cache, from oldest to newest. Keys() []interface{} // Len returns the number of items in the cache. Len() int // Purge clears all cache entries. Purge() }
ConcurrentCounterCache cache the hotspot parameter
func NewLRUCacheMap ¶
func NewLRUCacheMap(size int) ConcurrentCounterCache
type EvictCallback ¶
type EvictCallback func(key interface{}, value interface{})
EvictCallback is used to get a callback when a cache entry is evicted
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements a non-thread safe fixed size LRU cache
func NewLRU ¶
func NewLRU(size int, onEvict EvictCallback) (*LRU, error)
NewLRU constructs an LRU of the given size
func (*LRU) AddIfAbsent ¶
func (c *LRU) AddIfAbsent(key interface{}, value interface{}) (priorValue interface{})
AddIfAbsent adds item only if key is not existed.
func (*LRU) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*LRU) Keys ¶
func (c *LRU) Keys() []interface{}
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*LRU) Peek ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*LRU) Remove ¶
Remove removes the provided key from the cache, returning if the key was contained.
func (*LRU) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
type LruCacheMap ¶
type LruCacheMap struct {
// contains filtered or unexported fields
}
LruCacheMap use LRU strategy to cache the most frequently accessed hotspot parameter
func (*LruCacheMap) Add ¶
func (c *LruCacheMap) Add(key interface{}, value *int64)
func (*LruCacheMap) AddIfAbsent ¶
func (c *LruCacheMap) AddIfAbsent(key interface{}, value *int64) (priorValue *int64)
func (*LruCacheMap) Contains ¶
func (c *LruCacheMap) Contains(key interface{}) (ok bool)
func (*LruCacheMap) Get ¶
func (c *LruCacheMap) Get(key interface{}) (value *int64, isFound bool)
func (*LruCacheMap) Keys ¶
func (c *LruCacheMap) Keys() []interface{}
func (*LruCacheMap) Len ¶
func (c *LruCacheMap) Len() int
func (*LruCacheMap) Purge ¶
func (c *LruCacheMap) Purge()
func (*LruCacheMap) Remove ¶
func (c *LruCacheMap) Remove(key interface{}) (isFound bool)