Documentation ¶
Overview ¶
Package lru implements an LRU cache.
Index ¶
- type Cache
- type Key
- type List
- func (l *List) Back() *list.Element
- func (l *List) Front() *list.Element
- func (l *List) Init() *List
- func (l *List) InsertAfter(v interface{}, mark *list.Element) *list.Element
- func (l *List) InsertBefore(v interface{}, mark *list.Element) *list.Element
- func (l *List) Len() int
- func (l *List) MoveAfter(e, mark *list.Element)
- func (l *List) MoveBefore(e, mark *list.Element)
- func (l *List) MoveToBack(e *list.Element)
- func (l *List) MoveToFront(e *list.Element)
- func (l *List) PushBack(v interface{}) *list.Element
- func (l *List) PushBackList(other *List)
- func (l *List) PushFront(v interface{}) *list.Element
- func (l *List) PushFrontList(other *List)
- func (l *List) Remove(e *list.Element) interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache 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 }
Cache 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 (*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 List ¶
List is thread safe list base on list.List
func (*List) InsertAfter ¶
func (*List) InsertBefore ¶
func (*List) MoveBefore ¶
func (*List) MoveToBack ¶
func (*List) MoveToFront ¶
func (*List) PushBackList ¶
func (*List) PushFrontList ¶
Click to show internal directories.
Click to hide internal directories.