Skip to content

rselbach/lru

Repository files navigation

Generic LRU Cache for Go

Go Reference

A thread-safe, generic LRU cache implementation in Go with optional TTL expiration and eviction callbacks.

Features

  • Generic implementation (Go 1.18+)
  • O(1) lookups, insertions, and deletions
  • Thread-safe for concurrent access
  • Optional time-based expiration ([Expirable])
  • Eviction callbacks

Installation

go get github.com/rselbach/lru

Quick Start

cache := 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.

License

MIT License

About

Least-Recently Used cache implementations

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages