dboslee / lru

LRU cache using go generics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LRU Cache

A simple LRU cache using go generics.

Examples

Basic usage.

func main() {
    cache := lru.New[string, string]()
    cache.Set("key", "value")
    value, _ := cache.Get("key")
    fmt.Println(value)
}

Set the capacity using the lru.WithCapacity option. The default capacity is set to 10000.

func main() {
    cache := lru.New[string, string](lru.WithCapacity(100))
    ...
}

A thread safe implementation is included for convenience.

func main() {
    cache := lru.NewSync[string, string](lru.WithCapacity(100))
    ...
}

About

LRU cache using go generics

License:MIT License


Languages

Language:Go 100.0%