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(k1 K1, k2 K2) bool
- 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))
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(k1 K1, k2 K2) bool
RemoveKey2 remove the entry in the second layer
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
Click to show internal directories.
Click to hide internal directories.