Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

ristretto

> 数据库
Open source

A high performance memory-bound Go cache

7.0K stars0 likes0 views
WebsiteGitHub

About

A high performance memory-bound Go cache

# Ristretto Ristretto is a fast, concurrent cache library built with a focus on performance and correctness. The motivation to build Ristretto comes from the need for a contention-free cache in [Dgraph][]. [Dgraph]: https://github.com/dgraph-io/dgraph ## Features - **High Hit Ratios** - with our unique admission/eviction policy pairing, Ristretto's performance is best in class. - **Eviction: SampledLFU** - on par with exact LRU and better performance on Search and Database traces. - **Admission: TinyLFU** - extra performance with little memory overhead (12 bits per counter). - **Fast Throughput** - we use a variety of techniques for managing contention and the result is excellent throughput. - **Cost-Based Eviction** - any large new item deemed valuable can evict multiple smaller items (cost could be anything). - **Fully Concurrent** - you can use as many goroutines as you want with little throughput degradation. - **Metrics** - optional performance metrics for throughput, hit ratios, and other stats. - **Simple API** - just figure out your ideal `Config` values and you're off and running. ## Status Ristretto is production-ready. See [Projects using Ristretto](#projects-using-ristretto). ## Getting Started ### Installing To start using Ristretto, install Go 1.21 or above. Ristretto needs go modules. From your project, run the following command ```sh go get github.com/dgraph-io/ristretto/v2 ``` This will retrieve the library. #### Choosing a version Following these rules: - v1.x.x is the first version used in most programs with Ristretto dependencies. - v2.x.x is the new version with support for generics, for which it has a slightly different interface. This version is designed to solve compatibility problems of programs using the old version of Ristretto. If you start writing a new program, it is recommended to use this version. ## Usage ``` … ``` ## Benchmarks The benchmarks can be found in https://github.com/dgraph-io/dgraph-benchmarks/tree/main/cachebench/ristretto. ### Hit Ratios for Search This trace is described as "disk read accesses initiated by a large commercial search engine in response to various web search requests."

### Hit Ratio for Database This trace is described as "a database server running at a commercial site running an ERP application on top of a commercial database."

### Hit Ratio for Looping This trace demonstrates a looping access pattern.

### Hit Ratio for CODASYL This trace is described as "references to a CODASYL database for a one hour period."

### Throughput for Mixed Workload

### Throughput for Read Workload

### Through for Write Workload

## Projects Using Ristretto Below is a list of known projects that use Ristretto: - [Badger](https://github.com/dgraph-io/badger) - Embeddable key-value DB in Go - [Dgraph](https://github.com/dgraph-io/dgraph) - Horizontally scalable and distributed GraphQL database with a graph backend ## FAQ ### How are you achieving this performance? What shortcuts are you taking? We go into detail in the [Ristretto blog post](https://discuss.dgraph.io/t/introducing-ristretto-a-high-performance-go-cache-dgraph-blog/5102), but in short: our throughput performance can be attributed to a mix of batching and eventual consistency. Our hit ratio performance is mostly due to an excellent [admission policy](https://arxiv.org/abs/1512.00727) and SampledLFU eviction policy. As for "shortcuts," the only thing Ristretto does that could be construed as one is dropping some Set calls. That means a Set call for a new item (updates are guaranteed) isn't guaranteed to make it into the cache. The new item could be dropped at two points: when passing through the Set buffer or when passing through the admission policy. However, this doesn't affect hit ratios much at all as we expect the most popular items to be Set multiple times and eventually make it in the cache. ### Is Ristretto distributed? No, it's just like any other Go library that you can import into your project and use in a single process.

GitHub Issues· 0 open

View all on GitHub

No open issues yet, or sync has not completed.

Highlights

  • •High Hit Ratios - with our unique admission/eviction policy pairing, Ristretto's performance
  • •Eviction: SampledLFU - on par with exact LRU and better performance on Search and Database
  • •Admission: TinyLFU - extra performance with little memory overhead (12 bits per counter).
  • •Fast Throughput - we use a variety of techniques for managing contention and the result is
  • •Cost-Based Eviction - any large new item deemed valuable can evict multiple smaller items
  • •Fully Concurrent - you can use as many goroutines as you want with little throughput
  • •Metrics - optional performance metrics for throughput, hit ratios, and other stats.
  • •Simple API - just figure out your ideal Config values and you're off and running.
  • •v1.x.x is the first version used in most programs with Ristretto dependencies.
  • •v2.x.x is the new version with support for generics, for which it has a slightly different

> Tags

Gocachegogolanglibrary

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库