Documentation ¶
Overview ¶
Package lru implements cache with least recent used eviction policy.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] interface { Get(key K) *V Set(key K, value V) *V }
Cache defines minimal interface for all cache implementations, that requires two methods: Get and Set.
type LRU ¶
type LRU[K comparable, V any] struct { // contains filtered or unexported fields }
LRU implements Cache interface with least recent used eviction policy.
Example ¶
package main import ( "fmt" "github.com/floatdrop/lru" ) func main() { cache := lru.New[string, int](256) cache.Set("Hello", 5) fmt.Println(*cache.Get("Hello")) }
Output: 5
func New ¶
func New[K comparable, V any](size int) *LRU[K, V]
New creates LRU cache with size capacity. Cache will preallocate size count of internal structures to avoid allocation in process.
Click to show internal directories.
Click to hide internal directories.