Documentation
¶
Overview ¶
Package cache holds cache related files
Index ¶
- type TwoLayersLRU
- func (tll *TwoLayersLRU[K1, K2, V]) Add(k1 K1, k2 K2, v V) bool
- func (tll *TwoLayersLRU[K1, K2, V]) Get(k1 K1, k2 K2) (v V, ok bool)
- func (tll *TwoLayersLRU[K1, K2, V]) Len() int
- func (tll *TwoLayersLRU[K1, K2, V]) RemoveKey1(k1 K1) bool
- func (tll *TwoLayersLRU[K1, K2, V]) RemoveKey2(k2 K2, keys ...K1) int
- func (tll *TwoLayersLRU[K1, K2, V]) RemoveOldest() (K1, K2, V, bool)
- func (tll *TwoLayersLRU[K1, K2, V]) Walk(cb func(k1 K1, k2 K2, v V))
- func (tll *TwoLayersLRU[K1, K2, V]) WalkInner(k1 K1, cb func(k2 K2, v V) bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TwoLayersLRU ¶
type TwoLayersLRU[K1 comparable, K2 comparable, V any] struct { sync.RWMutex // contains filtered or unexported fields }
TwoLayersLRU defines a two layers LRU cache.
func NewTwoLayersLRU ¶
func NewTwoLayersLRU[K1 comparable, K2 comparable, V any](size int) (*TwoLayersLRU[K1, K2, V], error)
NewTwoLayersLRU returns a new cache.
func (*TwoLayersLRU[K1, K2, V]) Add ¶
func (tll *TwoLayersLRU[K1, K2, V]) Add(k1 K1, k2 K2, v V) bool
Add adds a value to the cache. Returns true if an eviction occurred.
func (*TwoLayersLRU[K1, K2, V]) Get ¶
func (tll *TwoLayersLRU[K1, K2, V]) Get(k1 K1, k2 K2) (v V, ok bool)
Get looks up key values from the cache.
func (*TwoLayersLRU[K1, K2, V]) Len ¶
func (tll *TwoLayersLRU[K1, K2, V]) Len() int
Len returns the number of entries
func (*TwoLayersLRU[K1, K2, V]) RemoveKey1 ¶
func (tll *TwoLayersLRU[K1, K2, V]) RemoveKey1(k1 K1) bool
RemoveKey1 the whole layer 2 for the given key1.
func (*TwoLayersLRU[K1, K2, V]) RemoveKey2 ¶
func (tll *TwoLayersLRU[K1, K2, V]) RemoveKey2(k2 K2, keys ...K1) int
RemoveKey2 removes the entry in the second layer for the given K1 keys. If no keys are provided, the function will try to remove the entry for all the keys. Returns the total number of entries that were removed from the cache.
func (*TwoLayersLRU[K1, K2, V]) RemoveOldest ¶
func (tll *TwoLayersLRU[K1, K2, V]) RemoveOldest() (K1, K2, V, bool)
RemoveOldest removes the oldest element
func (*TwoLayersLRU[K1, K2, V]) Walk ¶
func (tll *TwoLayersLRU[K1, K2, V]) Walk(cb func(k1 K1, k2 K2, v V))
Walk through all the keys
func (*TwoLayersLRU[K1, K2, V]) WalkInner ¶
func (tll *TwoLayersLRU[K1, K2, V]) WalkInner(k1 K1, cb func(k2 K2, v V) bool)
WalkInner through all the keys of the inner LRU