Documentation ¶
Index ¶
- type Callback
- type LRUCache
- func (lc *LRUCache) AdjustCapacity(bufCap int) (numEvicted int)
- func (lc *LRUCache) Capacity() int
- func (lc *LRUCache) Del(key interface{}) (wasDeleted bool)
- func (lc *LRUCache) Drop()
- func (lc *LRUCache) Get(key interface{}) (value interface{}, ok bool)
- func (lc *LRUCache) Has(key interface{}) (ok bool)
- func (lc *LRUCache) Keys() []interface{}
- func (lc *LRUCache) LeastRecentlyUsed() (key interface{}, value interface{})
- func (lc *LRUCache) Put(key, value interface{}) (wasEvicted bool)
- func (lc *LRUCache) Size() int
- type LRUController
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
func New ¶
New initializes a new LRU cache with a buffer capacity of `bufCap` It accepts as a second parameter a callback to be invoked upon successful invocation of the Least Recently-Used cache policy i.e. when a key/value pair is removed All transactions utilize locks and are therefore thread-safe
func (*LRUCache) AdjustCapacity ¶
AdjustCapacity resizes the cache capacity Invoking this transaction will evict all least recently-used items to adjust the cache, where necessary
func (*LRUCache) Del ¶
Del deletes an item corresponding to a given key from the cache, if extant A boolean flag is returned, indicating whether of not the transaction occurred
func (*LRUCache) Get ¶
Get attempts to retrieve the value for the given key from the cache Returns the corresponding value and true if extant; else, returns nil, false Get transactions will move the item to the head of the cache, designating it as most recently-used
func (*LRUCache) Has ¶
Has returns a boolean flag verifying the existence (or lack thereof) of a given key in the cache without enacting the eviction policy
func (*LRUCache) Keys ¶
func (lc *LRUCache) Keys() []interface{}
Keys returns a slice of the keys currently extant in the cache
func (*LRUCache) LeastRecentlyUsed ¶
func (lc *LRUCache) LeastRecentlyUsed() (key interface{}, value interface{})
LeastRecentlyUsed returns the least recently-used key / value pair, or nil if not extant
func (*LRUCache) Put ¶
Put adds or inserts a given key / value pair into the cache Put transactions will move the key to the head of the cache, designating it as 'most recently-used' If the cache has reached the specified capacity, Put transactions will also enact the eviction policy thereby removing the least recently-used item Returns a boolean flag indicating whether an eviction occurred
type LRUController ¶
type LRUController interface { Get(key interface{}) (value interface{}, ok bool) Put(key, value interface{}) (wasEvicted bool) Del(key interface{}) (wasDeleted bool) Keys() []interface{} Peek(key interface{}) (value interface{}) Has(key interface{}) (ok bool) Purge() Size() int AdjustCapacity(bufCap int) (numEvicted int) }