Documentation ¶
Overview ¶
Package cache Package lru implements an LRU cache.
Index ¶
- type Cache
- func (c *Cache) Add(key Key, value interface{})
- func (c *Cache) Clear()
- func (c *Cache) Contains(key interface{}) bool
- func (c *Cache) Get(key interface{}) (value interface{}, ok bool)
- func (c *Cache) Keys() []interface{}
- func (c *Cache) Length() int
- func (c *Cache) Remove(key interface{})
- func (c *Cache) RemoveOldest()
- type Key
- type Lru
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 is a thread-safe fixed size LRU cache.
func (*Cache) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*Cache) Keys ¶
func (c *Cache) Keys() []interface{}
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*Cache) Remove ¶
func (c *Cache) Remove(key interface{})
Remove removes the provided key from the cache.
func (*Cache) RemoveOldest ¶
func (c *Cache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
type Key ¶
type Key interface{}
A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
type Lru ¶
type Lru struct { // MaxEntries is the maximum number of cache entries before // an item is evicted. Zero means no limit. MaxEntries int // OnEvicted optionally specifies a callback function to be // executed when an entry is purged from the cache. OnEvicted func(key Key, value interface{}) // contains filtered or unexported fields }
Lru is an LRU cache. It is not safe for concurrent access.
func New ¶
New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*Lru) RemoveOldest ¶
func (c *Lru) RemoveOldest()
RemoveOldest removes the oldest item from the cache.