Documentation
¶
Overview ¶
Package lru implements an LRU cache.
Index ¶
- type Cache
- type Key
- type LRUCache
- func (c *LRUCache) Add(key Key, value interface{})
- func (c *LRUCache) Clear()
- func (c *LRUCache) ForEach(fn func(key Key, value interface{}))
- func (c *LRUCache) Get(key Key) (value interface{}, ok bool)
- func (c *LRUCache) Len() int
- func (c *LRUCache) Remove(key Key)
- func (c *LRUCache) RemoveOldest()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
func NewWithoutRWMutex ¶ added in v0.1.0
NewWithoutRWMutex create a new cache without rw mutex
type Key ¶ added in v0.2.0
type Key interface{}
A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
type LRUCache ¶ added in v0.2.0
type LRUCache 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 }
LRUCache is an LRU cache. It is not safe for concurrent access.
func NewLRU ¶ added in v0.2.0
New creates a new LRUCache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*LRUCache) Clear ¶ added in v0.2.0
func (c *LRUCache) Clear()
Clear purges all stored items from the cache.
func (*LRUCache) RemoveOldest ¶ added in v0.2.0
func (c *LRUCache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
Click to show internal directories.
Click to hide internal directories.