A high-performance, concurrent cache library for Go with cost-based eviction and excellent hit ratios.
Ristretto is a high-performance, concurrent cache library written in Go, designed for memory-bound caching scenarios. It solves the problem of efficiently managing cache eviction and admission to maximize hit ratios and throughput, particularly in high-concurrency applications like databases and search engines. Its unique combination of TinyLFU admission and SampledLFU eviction policies ensures excellent performance across various workloads.
Go developers building high-performance applications that require efficient in-memory caching, such as database systems (e.g., Dgraph, Badger), search engines, or any service needing low-latency data access with high concurrency.
Developers choose Ristretto for its best-in-class hit ratios, fully concurrent design, and cost-based eviction, which together provide superior performance compared to other Go cache libraries. Its focus on correctness and simplicity, coupled with optional metrics, makes it a reliable choice for production systems.
A high performance memory-bound Go cache
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses TinyLFU admission and SampledLFU eviction policies, with benchmarks showing superior performance on search, database, and looping traces compared to alternatives like ARC and LIRS.
Designed to be contention-free with techniques like batching, enabling excellent throughput even with many goroutines, as evidenced by mixed workload benchmarks.
Allows eviction based on any cost metric (e.g., memory size), so large valuable items can displace multiple smaller ones, optimizing cache efficiency.
Requires only a few Config values like NumCounters and MaxCost to get started, making integration straightforward for Go developers.
Set operations for new items are not guaranteed to be cached, as they can be dropped in buffers or by the admission policy, which may not suit use cases requiring immediate write consistency.
Ristretto is purely an in-memory cache with no native persistence mechanisms, so data is lost on process restart, requiring external solutions for durability.
Performance heavily depends on tuning parameters like NumCounters and BufferItems, which may require benchmarking and adjustment for specific workloads, adding complexity.