Documentation ¶
Index ¶
- type EvictCallback
- type EvictionReason
- type Field
- type FieldValue
- type LRU
- func (l *LRU) Add(key Field, value Value) bool
- func (l *LRU) Cap() int
- func (l *LRU) Capacity() bool
- func (l *LRU) Contains(key Field) bool
- func (l *LRU) Dequeue(fn func(Field, Value) error) ([]FieldValue, error)
- func (l *LRU) Get(key Field) (value Value, ok bool)
- func (l *LRU) Keys() []Field
- func (l *LRU) Len() int
- func (l *LRU) Peek(key Field) (value Value, ok bool)
- func (l *LRU) Pop() (Field, Value, bool)
- func (l *LRU) Purge()
- func (l *LRU) Remove(key Field) (ok bool)
- func (l *LRU) Slice() []FieldValue
- func (l *LRU) Walk(fn func(Field, Value) error) (err error)
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvictCallback ¶
type EvictCallback func(EvictionReason, Field, Value)
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 FieldValue ¶
FieldValue is a tuple to both Field and Value type
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) Peek ¶
Peek returns a value, without marking the LRU cache. Returns true if a value is found.
func (*LRU) Purge ¶
func (l *LRU) Purge()
Purge removes all items with in the cache, calling evict callback on each.
func (*LRU) Slice ¶
func (l *LRU) Slice() []FieldValue
Slice returns a snapshot of the FieldValue pairs.
Click to show internal directories.
Click to hide internal directories.