What problem does it solve?
It helps Go engineers design high-performance in-memory caching with samber/hot by selecting an eviction strategy, configuring TTL and loader behavior, and avoiding common runtime and correctness pitfalls.
Core Features & Use Cases
- Eviction algorithm selection (LRU/LFU/TinyLFU/W-TinyLFU/ARC/S3FIFO/SIEVE/TwoQueue/FIFO): Choose based on mixed versus stable access patterns and scan resistance needs.
- TTL, jitter, and background expiration (Janitor): Prevent stale data and reduce thundering herd effects.
- Loader patterns with singleflight deduplication + negative caching: Use WithLoaders to batch fetch on misses and optionally cache missing keys safely.
- Stale-while-revalidate and error policy controls: Serve stale data while refreshing asynchronously, with KeepOnError or DropOnError.
- Production hardening: Sharding to reduce lock contention, copy-on-read/write for mutable values, and Prometheus metrics for monitoring.
Quick Start
Use a W-TinyLFU cache with TTL, janitor cleanup, and Prometheus metrics, then add a loader function to batch-fetch missing keys safely when the cache expires.