API Reference

Ristretto

A high-performance, memory-bound Go cache with admission policies and built-in metrics.

Official Documentation ↗
CompatibilityThis documentation covers version v0.1. Check the official docs for the latest API surface.

Installation

gogo get github.com/dgraph-io/ristretto

Methods

Ristretto bounds cache memory and uses TinyLFU admission to keep frequently used items.

Key Features

  • Memory-bound with cost accounting
  • TinyLFU admission policy
  • Hit ratio metrics and TTL

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

API reference evidence

Fetched from official sources on 2026-11-08T16:02:45+08:00 via WebFetch pkg.go.dev + PowerShell Invoke-WebRequest raw.githubusercontent.com (dgraph-io/ristretto v0.2.0) + 模块 zip (proxy.golang.org v0.2.0).

FAQ

Why did Set return false?
The item was rejected by the admission policy or the store was at capacity; it is not an error but an admission decision.
What is the cost function?
A per-item size estimate that lets the cache bound total memory rather than just entry count.
How is it different from a plain map?
Ristretto bounds memory, evicts by policy, and records hit ratio, which a map does neither.