A thread-safe, generic LRU cache implementation in Go with optional TTL expiration and eviction callbacks.
- Generic implementation (Go 1.18+)
- O(1) lookups, insertions, and deletions
- Thread-safe for concurrent access
- Optional time-based expiration ([Expirable])
- Eviction callbacks
go get github.com/rselbach/lrucache := lru.MustNew[string, int](100)
cache.Set("key", 42)
value, found := cache.Get("key")With TTL expiration:
cache := lru.MustNewExpirable[string, int](100, 5*time.Minute)
cache.Set("key", 42)
value, ttl, found := cache.GetWithTTL("key")See the package documentation for complete API reference and examples.