Documentation
¶
Index ¶
- type EvictCallback
- type EvictionReason
- type KeyValue
- type LRU
- func (l *LRU) Add(key uuid.UUID, value models.Record) bool
- func (l *LRU) Cap() int
- func (l *LRU) Capacity() bool
- func (l *LRU) Contains(key uuid.UUID) bool
- func (l *LRU) Dequeue(fn func(uuid.UUID, models.Record) error) ([]KeyValue, error)
- func (l *LRU) Get(key uuid.UUID) (value models.Record, ok bool)
- func (l *LRU) Keys() []uuid.UUID
- func (l *LRU) Len() int
- func (l *LRU) Peek(key uuid.UUID) (value models.Record, ok bool)
- func (l *LRU) Pop() (uuid.UUID, models.Record, bool)
- func (l *LRU) Purge()
- func (l *LRU) Remove(key uuid.UUID) (ok bool)
- func (l *LRU) Slice() []KeyValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvictCallback ¶
type EvictCallback func(EvictionReason, uuid.UUID, models.Record)
EvictCallback lets you know when an eviction has happened in the cache
type EvictionReason ¶
type EvictionReason int
EvictionReason describes why the eviction happened
const ( // Purged by calling reset Purged EvictionReason = iota // Popped manually from the cache Popped // Removed manually from the cache Removed // Dequeued by walking over due to being dequeued Dequeued )
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements a non-thread safe fixed size LRU cache
func NewLRU ¶
func NewLRU(size int, onEvict EvictCallback) *LRU
NewLRU creates a LRU cache with a size and callback on eviction
func (*LRU) Add ¶
Add adds a key, value pair. Returns true if an eviction happened.
func (*LRU) Capacity ¶
Capacity returns if the LRU cache is at capacity or not.
func (*LRU) Contains ¶
Contains finds out if a key is present in the LRU cache
func (*LRU) Dequeue ¶
Dequeue iterates over the LRU cache removing an item upon each iteration.
func (*LRU) Get ¶
Get returns back a value if it exists. Returns true if found.
func (*LRU) Peek ¶
Peek returns a value, without marking the LRU cache. Returns true if a value is found.
func (*LRU) Pop ¶
Pop removes the last LRU item with in the cache
func (*LRU) Purge ¶
func (l *LRU) Purge()
Purge removes all items with in the cache, calling evict callback on each.
func (*LRU) Remove ¶
Remove a value using it's key Returns true if a removal happened
Source Files
¶
- list.go
- lru.go