Documentation ¶
Index ¶
- Constants
- type LRU
- func (lru *LRU) Clear()
- func (lru *LRU) Contains(key interface{}) bool
- func (lru *LRU) Delete(key interface{}) (prev interface{}, deleted bool)
- func (lru *LRU) Get(key interface{}) (value interface{}, ok bool)
- func (lru *LRU) Len() int
- func (lru *LRU) Peek(key interface{}) (value interface{}, ok bool)
- func (lru *LRU) Range(iter func(key interface{}, value interface{}) bool)
- func (lru *LRU) Resize(size int) (evictedKeys []interface{}, evictedValues []interface{})
- func (lru *LRU) Reverse(iter func(key interface{}, value interface{}) bool)
- func (lru *LRU) Set(key interface{}, value interface{}) (prev interface{}, replaced bool)
- func (lru *LRU) SetEvicted(key interface{}, value interface{}) (prev interface{}, replaced bool, evictedKey interface{}, ...)
- type LRUG
- func (lru *LRUG[Key, Value]) Clear()
- func (lru *LRUG[Key, Value]) Contains(key Key) bool
- func (lru *LRUG[Key, Value]) Delete(key Key) (prev Value, deleted bool)
- func (lru *LRUG[Key, Value]) Get(key Key) (value Value, ok bool)
- func (lru *LRUG[Key, Value]) Len() int
- func (lru *LRUG[Key, Value]) Peek(key Key) (value Value, ok bool)
- func (lru *LRUG[Key, Value]) Range(iter func(key Key, value Value) bool)
- func (lru *LRUG[Key, Value]) Resize(size int) (evictedKeys []Key, evictedValues []Value)
- func (lru *LRUG[Key, Value]) Reverse(iter func(key Key, value Value) bool)
- func (lru *LRUG[Key, Value]) Set(key Key, value Value) (prev Value, replaced bool)
- func (lru *LRUG[Key, Value]) SetEvicted(key Key, value Value) (prev Value, replaced bool, evictedKey Key, evictedValue Value, evicted bool)
Constants ¶
const DefaultSize = 256
DefaultSize is the default maximum size of an LRU cache before older items get automatically evicted.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements an LRU cache
func (*LRU) Clear ¶ added in v1.2.1
func (lru *LRU) Clear()
Clear will remove all key/values from the LRU cache
func (*LRU) Peek ¶ added in v1.1.0
Peek returns the value for key value without updating the recently used status.
func (*LRU) Range ¶
Range iterates over all key/values in the order of most recently to least recently used items.
func (*LRU) Resize ¶
Resize sets the maximum size of an LRU cache. If this value is less than the number of items currently in the cache, then items will be evicted. Returns evicted items. This operation will panic if the size is less than one.
func (*LRU) Reverse ¶
Reverse iterates over all key/values in the order of least recently to most recently used items.
func (*LRU) SetEvicted ¶
func (lru *LRU) SetEvicted(key interface{}, value interface{}) ( prev interface{}, replaced bool, evictedKey interface{}, evictedValue interface{}, evicted bool)
SetEvicted sets or replaces a value for a key. If this operation causes an eviction then the evicted item is returned.
type LRUG ¶ added in v1.2.0
type LRUG[Key comparable, Value any] struct { // contains filtered or unexported fields }
LRUG implements an LRU cache
func (*LRUG[Key, Value]) Clear ¶ added in v1.2.1
func (lru *LRUG[Key, Value]) Clear()
Clear will remove all key/values from the LRU cache
func (*LRUG[Key, Value]) Peek ¶ added in v1.2.0
Peek returns the value for key value without updating the recently used status.
func (*LRUG[Key, Value]) Range ¶ added in v1.2.0
Range iterates over all key/values in the order of most recently to least recently used items.
func (*LRUG[Key, Value]) Resize ¶ added in v1.2.0
Resize sets the maximum size of an LRU cache. If this value is less than the number of items currently in the cache, then items will be evicted. Returns evicted items. This operation will panic if the size is less than one.
func (*LRUG[Key, Value]) Reverse ¶ added in v1.2.0
Reverse iterates over all key/values in the order of least recently to most recently used items.
func (*LRUG[Key, Value]) SetEvicted ¶ added in v1.2.0
func (lru *LRUG[Key, Value]) SetEvicted(key Key, value Value) ( prev Value, replaced bool, evictedKey Key, evictedValue Value, evicted bool)
SetEvicted sets or replaces a value for a key. If this operation causes an eviction then the evicted item is returned.