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
go
go get github.com/dgraph-io/ristrettoMethods
No methods match this filter.
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).
ristretto.NewCache→ signature from https://raw.githubusercontent.com/dgraph-io/ristretto/v0.2.0/cache.go; official text: “func NewCache(config *Config) (*Cache, error) {”Cache.Set→ signature from https://raw.githubusercontent.com/dgraph-io/ristretto/v0.2.0/cache.go; official text: “func (c *Cache) Set(key, value interface{}, cost int64) bool {”Cache.Get→ signature from https://raw.githubusercontent.com/dgraph-io/ristretto/v0.2.0/cache.go; official text: “func (c *Cache) Get(key interface{}) (interface{}, bool) {”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.