Generic thread-safe LRU (Least Recently Used) cache for Go.
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 anAll()loop — it will deadlock. Collect keys first if you need to modify while iterating.
MIT