Ristretto is a high-performance, memory-bound cache library for Go that prioritizes concurrent access and hit ratio optimization.
The library addresses the need for a contention-free cache by combining two specialized policies: SampledLFU for eviction and TinyLFU for admission. This pairing is designed to achieve high hit ratios across diverse workload patterns while maintaining excellent throughput under concurrent access. The tool uses cost-based eviction, allowing valuable large items to displace multiple smaller items when needed, and employs various contention-management techniques to support many goroutines with minimal performance degradation. Optional metrics provide visibility into throughput, hit ratios, and other performance characteristics.
Ristretto suits projects where cache performance directly impacts application responsiveness and where concurrent access patterns are common. The library offers two major versions: the original v1.x.x for existing programs and v2.x.x with generics support and a revised interface, recommended for new projects. The README benchmarks demonstrate hit ratio performance across search, database, looping, and CODASYL workload traces, as well as throughput comparisons for mixed and read-heavy scenarios. Configuration is straightforward, requiring developers to set appropriate Config values before use.
The project maintains active engagement with real-world usage, documenting production deployments. Development shows sustained attention to both correctness and performance optimization, with the codebase supporting multiple Go versions and providing clear upgrade paths between major versions. The project includes comprehensive benchmarking infrastructure and maintains documentation of performance characteristics across different access patterns.