Documentation ¶
Overview ¶
Package lru implements a Least-Recently-Used (LRU) cache of objects keyed by a string.
A given key can have multiple values associated with it in the cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements a Least-Recently-Used cache of objects. Cache objects are not safe for concurrent use.
func (*Cache) Get ¶
Get returns a value in the cache associated with the provided key and removes it from the cache's storage. It returns (nil, false) if no value is associated with the key.
If there are multiple values associated with the provided key, Get will return the most recently used one.
func (*Cache) Put ¶
func (c *Cache) Put(key string, value interface{}) (evictedKey string, evictedValue interface{}, evicted bool)
Put adds the provided (key, value) pair to the cache and returns the (key, value) pair that was evicted (if any) in order to make space for the provided pair.
It is legal to use the same key in multiple Put invocations as the cache can hold multiple values associated with the same key.