Documentation
¶
Overview ¶
Example ¶
cache := New[int, struct{}](8, func(key int, _ struct{}) { fmt.Println("evicted", key) }) for i := 1; i <= 10; i++ { cache.Replace(i, struct{}{}) } fmt.Printf("%d items in cache\n", cache.Len()) for k, v := range cache.IterateAsc() { fmt.Println(k, v) }
Output: evicted 1 evicted 2 8 items in cache 3 {} 4 {} 5 {} 6 {} 7 {} 8 {} 9 {} 10 {}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU[K comparable, V any] interface { Len() int Cap() int Resize(capacity int) Has(key K) (ok bool) Get(key K) (val V, ok bool) GetOrSet(key K, setter func(K) (V, error)) (val V, err error) Set(key K, val V) (ok bool) Replace(key K, val V) (existed bool) Remove(key K) (existed bool) Iterate() iter.Seq2[K, V] IterateAsc() iter.Seq2[K, V] IterateDesc() iter.Seq2[K, V] // Clear cache and notify each evict. To clear cache without notice, use Reset. RemoveAll() // Clear cache without notice. To clear cache and notify each evict, use RemoveAll. Reset() }
func NewThreadSafe ¶
func NewThreadSafe[K comparable, V any](capacity int, evicted ...func(key K, val V)) LRU[K, V]
Click to show internal directories.
Click to hide internal directories.