Ristretto — screenshot of github.com

Ristretto

Ristretto is a high-performance, memory-bound Go cache. It focuses on contention-free concurrency and cost-based eviction, offering excellent hit ratios and throughput.

Visit github.com →

Questions & Answers

What is Ristretto?
Ristretto is a fast, concurrent, and high-performance in-memory cache library written in Go. It was developed to provide a contention-free caching solution, focusing on performance and correctness for Go applications.
Who would benefit from using Ristretto?
Ristretto is suitable for Go developers building applications that require a high-performance, concurrent, and memory-bound cache. Projects like Dgraph and Badger utilize it for their caching needs, indicating its use in demanding database or distributed systems contexts.
How does Ristretto achieve high performance and differentiate itself from other caches?
Ristretto achieves high hit ratios and throughput through a unique admission/eviction policy pairing, specifically TinyLFU for admission and SampledLFU for eviction. It also features cost-based eviction and is designed to be fully concurrent, minimizing throughput degradation with multiple goroutines.
When should I consider using the Ristretto cache library in my Go project?
You should consider Ristretto when your Go application requires an in-process cache that can handle high concurrency with minimal contention, needs excellent hit ratios for memory efficiency, and can benefit from features like cost-based eviction. It is production-ready, especially recommended for new programs with Go 1.21+ using its v2 generics-supported interface.
What is the main characteristic of Ristretto's eviction policy?
Ristretto employs a SampledLFU (Least Frequently Used) eviction policy, paired with a TinyLFU admission policy. This combination ensures high hit ratios by efficiently managing which items are admitted and evicted from the cache, even under heavy load.