{"id":25038978,"url":"https://github.com/hypermodeinc/ristretto","last_synced_at":"2025-05-13T15:13:01.413Z","repository":{"id":37580315,"uuid":"170366344","full_name":"hypermodeinc/ristretto","owner":"hypermodeinc","description":"A high performance memory-bound Go cache","archived":false,"fork":false,"pushed_at":"2025-05-07T01:43:24.000Z","size":1582,"stargazers_count":6025,"open_issues_count":5,"forks_count":395,"subscribers_count":69,"default_branch":"main","last_synced_at":"2025-05-07T02:44:32.453Z","etag":null,"topics":["cache","go","golang","library","performance"],"latest_commit_sha":null,"homepage":"https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hypermodeinc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-02-12T18:07:00.000Z","updated_at":"2025-05-07T01:43:27.000Z","dependencies_parsed_at":"2023-02-10T03:01:13.059Z","dependency_job_id":"b035fc3e-ac5c-403e-b6b9-bb445d7b68dc","html_url":"https://github.com/hypermodeinc/ristretto","commit_stats":{"total_commits":332,"total_committers":44,"mean_commits":7.545454545454546,"dds":0.7319277108433735,"last_synced_commit":"34fd2d33a86ef2eeebb75f3f5d78909b180d7410"},"previous_names":["hypermodeinc/ristretto","dgraph-io/ristretto"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypermodeinc%2Fristretto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypermodeinc%2Fristretto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypermodeinc%2Fristretto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypermodeinc%2Fristretto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypermodeinc","download_url":"https://codeload.github.com/hypermodeinc/ristretto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969266,"owners_count":21992264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","go","golang","library","performance"],"created_at":"2025-02-06T02:02:39.534Z","updated_at":"2025-05-13T15:12:56.394Z","avatar_url":"https://github.com/hypermodeinc.png","language":"Go","readme":"# Ristretto\n\n[![GitHub License](https://img.shields.io/github/license/hypermodeinc/ristretto)](https://github.com/hypermodeinc/ristretto?tab=Apache-2.0-1-ov-file#readme)\n[![chat](https://img.shields.io/discord/1267579648657850441)](https://discord.hypermode.com)\n[![GitHub Repo stars](https://img.shields.io/github/stars/hypermodeinc/ristretto)](https://github.com/hypermodeinc/ristretto/stargazers)\n[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/hypermodeinc/ristretto)](https://github.com/hypermodeinc/ristretto/commits/main/)\n[![Go Report Card](https://img.shields.io/badge/go%20report-A%2B-brightgreen)](https://goreportcard.com/report/github.com/dgraph-io/ristretto)\n\nRistretto is a fast, concurrent cache library built with a focus on performance and correctness.\n\nThe motivation to build Ristretto comes from the need for a contention-free cache in [Dgraph][].\n\n[Dgraph]: https://github.com/hypermodeinc/dgraph\n\n## Features\n\n- **High Hit Ratios** - with our unique admission/eviction policy pairing, Ristretto's performance\n  is best in class.\n  - **Eviction: SampledLFU** - on par with exact LRU and better performance on Search and Database\n    traces.\n  - **Admission: TinyLFU** - extra performance with little memory overhead (12 bits per counter).\n- **Fast Throughput** - we use a variety of techniques for managing contention and the result is\n  excellent throughput.\n- **Cost-Based Eviction** - any large new item deemed valuable can evict multiple smaller items\n  (cost could be anything).\n- **Fully Concurrent** - you can use as many goroutines as you want with little throughput\n  degradation.\n- **Metrics** - optional performance metrics for throughput, hit ratios, and other stats.\n- **Simple API** - just figure out your ideal `Config` values and you're off and running.\n\n## Status\n\nRistretto is production-ready. See [Projects using Ristretto](#projects-using-ristretto).\n\n## Getting Started\n\n### Installing\n\nTo start using Ristretto, install Go 1.21 or above. Ristretto needs go modules. From your project,\nrun the following command\n\n```sh\ngo get github.com/dgraph-io/ristretto/v2\n```\n\nThis will retrieve the library.\n\n#### Choosing a version\n\nFollowing these rules:\n\n- v1.x.x is the first version used in most programs with Ristretto dependencies.\n- v2.x.x is the new version with support for generics, for which it has a slightly different\n  interface. This version is designed to solve compatibility problems of programs using the old\n  version of Ristretto. If you start writing a new program, it is recommended to use this version.\n\n## Usage\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n\n  \"github.com/dgraph-io/ristretto/v2\"\n)\n\nfunc main() {\n  cache, err := ristretto.NewCache(\u0026ristretto.Config[string, string]{\n    NumCounters: 1e7,     // number of keys to track frequency of (10M).\n    MaxCost:     1 \u003c\u003c 30, // maximum cost of cache (1GB).\n    BufferItems: 64,      // number of keys per Get buffer.\n  })\n  if err != nil {\n    panic(err)\n  }\n  defer cache.Close()\n\n  // set a value with a cost of 1\n  cache.Set(\"key\", \"value\", 1)\n\n  // wait for value to pass through buffers\n  cache.Wait()\n\n  // get value from cache\n  value, found := cache.Get(\"key\")\n  if !found {\n    panic(\"missing value\")\n  }\n  fmt.Println(value)\n\n  // del value from cache\n  cache.Del(\"key\")\n}\n```\n\n## Benchmarks\n\nThe benchmarks can be found in\nhttps://github.com/hypermodeinc/dgraph-benchmarks/tree/main/cachebench/ristretto.\n\n### Hit Ratios for Search\n\nThis trace is described as \"disk read accesses initiated by a large commercial search engine in\nresponse to various web search requests.\"\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hypermodeinc/ristretto/main/benchmarks/Hit%20Ratios%20-%20Search%20(ARC-S3).svg\"\n  alt=\"Graph showing hit ratios comparison for search workload\"\u003e\n\u003c/p\u003e\n\n### Hit Ratio for Database\n\nThis trace is described as \"a database server running at a commercial site running an ERP\napplication on top of a commercial database.\"\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hypermodeinc/ristretto/main/benchmarks/Hit%20Ratios%20-%20Database%20(ARC-DS1).svg\"\n  alt=\"Graph showing hit ratios comparison for database workload\"\u003e\n\u003c/p\u003e\n\n### Hit Ratio for Looping\n\nThis trace demonstrates a looping access pattern.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hypermodeinc/ristretto/main/benchmarks/Hit%20Ratios%20-%20Glimpse%20(LIRS-GLI).svg\"\n  alt=\"Graph showing hit ratios comparison for looping access pattern\"\u003e\n\u003c/p\u003e\n\n### Hit Ratio for CODASYL\n\nThis trace is described as \"references to a CODASYL database for a one hour period.\"\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hypermodeinc/ristretto/main/benchmarks/Hit%20Ratios%20-%20CODASYL%20(ARC-OLTP).svg\"\n  alt=\"Graph showing hit ratios comparison for CODASYL workload\"\u003e\n\u003c/p\u003e\n\n### Throughput for Mixed Workload\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hypermodeinc/ristretto/main/benchmarks/Throughput%20-%20Mixed.svg\"\n  alt=\"Graph showing throughput comparison for mixed workload\"\u003e\n\u003c/p\u003e\n\n### Throughput ffor Read Workload\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hypermodeinc/ristretto/main/benchmarks/Throughput%20-%20Read%20(Zipfian).svg\"\n  alt=\"Graph showing throughput comparison for read workload\"\u003e\n\u003c/p\u003e\n\n### Through for Write Workload\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hypermodeinc/ristretto/main/benchmarks/Throughput%20-%20Write%20(Zipfian).svg\"\n  alt=\"Graph showing throughput comparison for write workload\"\u003e\n\u003c/p\u003e\n\n## Projects Using Ristretto\n\nBelow is a list of known projects that use Ristretto:\n\n- [Badger](https://github.com/hypermodeinc/badger) - Embeddable key-value DB in Go\n- [Dgraph](https://github.com/hypermodeinc/dgraph) - Horizontally scalable and distributed GraphQL\n  database with a graph backend\n\n## FAQ\n\n### How are you achieving this performance? What shortcuts are you taking?\n\nWe go into detail in the\n[Ristretto blog post](https://hypermode.com/blog/introducing-ristretto-high-perf-go-cache/), but in\nshort: our throughput performance can be attributed to a mix of batching and eventual consistency.\nOur hit ratio performance is mostly due to an excellent\n[admission policy](https://arxiv.org/abs/1512.00727) and SampledLFU eviction policy.\n\nAs for \"shortcuts,\" the only thing Ristretto does that could be construed as one is dropping some\nSet calls. That means a Set call for a new item (updates are guaranteed) isn't guaranteed to make it\ninto the cache. The new item could be dropped at two points: when passing through the Set buffer or\nwhen passing through the admission policy. However, this doesn't affect hit ratios much at all as we\nexpect the most popular items to be Set multiple times and eventually make it in the cache.\n\n### Is Ristretto distributed?\n\nNo, it's just like any other Go library that you can import into your project and use in a single\nprocess.\n","funding_links":[],"categories":["Go","Database"],"sub_categories":["Caches"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypermodeinc%2Fristretto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypermodeinc%2Fristretto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypermodeinc%2Fristretto/lists"}