Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

lrucache

Generic thread-safe LRU (Least Recently Used) cache for Go.

Usage

import"github.com/AnthonyLonsMax/lrucache"c:= lrucache.New[string, int](100) // capacityc.Put("a", 1)
c.Put("b", 2)
v, ok:=c.Get("a") // 1, truec.Contains("a") // truec.Update("a", 99)
c.Delete("b")
// iteratefork, v:=rangec.All() {
fmt.Println(k, v)
}

When the cache exceeds capacity, the least recently used entry is evicted on insert.

Tip: Don't call mutating methods (Get, Put, Delete, etc.) inside an All() loop — it will deadlock. Collect keys first if you need to modify while iterating.

License

MIT

About

Generic thread-safe LRU cache for Go.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages