{"id":32174171,"url":"https://github.com/dgraph-io/ristretto","last_synced_at":"2026-01-22T00:01:23.465Z","repository":{"id":37580315,"uuid":"170366344","full_name":"dgraph-io/ristretto","owner":"dgraph-io","description":"A high performance memory-bound Go cache","archived":false,"fork":false,"pushed_at":"2025-12-10T21:10:12.000Z","size":1587,"stargazers_count":6666,"open_issues_count":10,"forks_count":431,"subscribers_count":72,"default_branch":"main","last_synced_at":"2026-01-14T13:58:14.670Z","etag":null,"topics":["cache","go","golang","library","performance"],"latest_commit_sha":null,"homepage":"https://hypermode.com/blog/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/dgraph-io.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-02-12T18:07:00.000Z","updated_at":"2026-01-14T11:25:08.000Z","dependencies_parsed_at":"2023-02-10T03:01:13.059Z","dependency_job_id":"b035fc3e-ac5c-403e-b6b9-bb445d7b68dc","html_url":"https://github.com/dgraph-io/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":16,"template":false,"template_full_name":null,"purl":"pkg:github/dgraph-io/ristretto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fristretto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fristretto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fristretto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fristretto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgraph-io","download_url":"https://codeload.github.com/dgraph-io/ristretto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fristretto/sbom","scorecard":{"id":1241650,"data":{"date":"2026-01-12","repo":{"name":"github.com/dgraph-io/ristretto","commit":"4f24d62b5137e5788009d6f23b75502c8a3ead46"},"scorecard":{"version":"v5.4.1-0.20260109214540-85483c21ffbb","commit":"85483c21ffbb0f125cf1d16aa53f283d574f4ca5"},"score":5.3,"checks":[{"name":"Code-Review","score":5,"reason":"Found 9/16 approved changesets -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#packaging"}},{"name":"Maintained","score":5,"reason":"5 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#maintained"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#security-policy"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: topLevel 'contents' permission set to 'read': .github/workflows/ci-ristretto-tests.yml:17","Info: topLevel 'contents' permission set to 'read': .github/workflows/trunk.yml:7","Warn: topLevel 'actions' permission set to 'write': .github/workflows/trunk.yml:8","Warn: topLevel 'checks' permission set to 'write': .github/workflows/trunk.yml:9","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-ristretto-tests.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/dgraph-io/ristretto/ci-ristretto-tests.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-ristretto-tests.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/dgraph-io/ristretto/ci-ristretto-tests.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-ristretto-tests.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/dgraph-io/ristretto/ci-ristretto-tests.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/trunk.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/dgraph-io/ristretto/trunk.yml/main?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#cii-best-practices"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: 'allow deletion' enabled on branch 'main'","Warn: 'force pushes' enabled on branch 'main'","Info: 'branch protection settings apply to administrators' is required to merge on branch 'main'","Warn: could not determine whether codeowners review is allowed","Warn: 'up-to-date branches' is disabled on branch 'main'","Info: status check found to merge onto on branch 'main'","Warn: PRs are not required to make changes on branch 'main'; or we don't have data to detect it.If you think it might be the latter, make sure to run Scorecard with a PAT or use Repo Rules (that are always public) instead of Branch Protection settings"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":5,"reason":"SAST tool is not run on all commits -- score normalized to 5","details":["Warn: 15 commits out of 26 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#sast"}}]},"last_synced_at":"2026-01-14T16:13:35.023Z","repository_id":37580315,"created_at":"2026-01-14T16:13:35.023Z","updated_at":"2026-01-14T16:13:35.023Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28647470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T21:29:11.980Z","status":"ssl_error","status_checked_at":"2026-01-21T21:24:31.872Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-10-21T19:01:10.419Z","updated_at":"2026-01-22T00:01:23.418Z","avatar_url":"https://github.com/dgraph-io.png","language":"Go","readme":"# Ristretto\n\n[![GitHub License](https://img.shields.io/github/license/dgraph-io/ristretto)](https://github.com/dgraph-io/ristretto?tab=Apache-2.0-1-ov-file#readme)\n[![GitHub Repo stars](https://img.shields.io/github/stars/dgraph-io/ristretto)](https://github.com/dgraph-io/ristretto/stargazers)\n[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/dgraph-io/ristretto)](https://github.com/dgraph-io/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/dgraph-io/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/dgraph-io/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/dgraph-io/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/dgraph-io/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/dgraph-io/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/dgraph-io/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/dgraph-io/ristretto/main/benchmarks/Throughput%20-%20Mixed.svg\"\n  alt=\"Graph showing throughput comparison for mixed workload\"\u003e\n\u003c/p\u003e\n\n### Throughput for Read Workload\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/dgraph-io/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/dgraph-io/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/dgraph-io/badger) - Embeddable key-value DB in Go\n- [Dgraph](https://github.com/dgraph-io/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://web.archive.org/web/20250806164019/https://hypermode.com/blog/introducing-ristretto-high-perf-go-cache),\nbut in short: our throughput performance can be attributed to a mix of batching and eventual\nconsistency. Our 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":["开源类库","Database","数据库","Go","Open source library","Cache","Go (134)","Data Integration Frameworks","Repositories"],"sub_categories":["缓存","Caches","Cache"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgraph-io%2Fristretto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgraph-io%2Fristretto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgraph-io%2Fristretto/lists"}