What it does
High-performance in-process caching with multiple eviction policies (LRU, LFU, TinyLFU, TTL, size-bounded). Async-safe, lock-minimized internals. Typed key-value API. No dependency on any external store.
Quick start
[]
= "1"
use Duration;
use ;
// LRU — evicts the least-recently-accessed entry on overflow.
let lru: = new.expect;
lru.insert;
assert_eq!;
// LFU — evicts the lowest-counter entry on overflow.
let lfu: = new.expect;
lfu.insert;
// TTL — entries expire after their per-entry deadline; lazy expiry on access.
let ttl: =
new.expect;
ttl.insert_with_ttl;
// TinyLFU — Count-Min Sketch admission filter rejects cold candidates.
let tinylfu: = new.expect;
tinylfu.insert;
// SizedCache — capacity is total byte-weight, not entry count.
let sized: =
new.expect;
sized.insert;
FEATURES
Cache<K, V>trait — the common read / write / evict contract.LruCache<K, V>— bounded, thread-safe Least-Recently-Used cache.LfuCache<K, V>— bounded, thread-safe Least-Frequently-Used cache.TtlCache<K, V>— bounded, thread-safe Time-To-Live cache with lazy expiry.TinyLfuCache<K, V>— Count-Min Sketch admission filter + LRU main cache.SizedCache<K, V>— capacity bound is total byte-weight across entries.CacheError— error type returned by constructors.
Arena-backed internals (O(1) for LRU/TinyLFU/Sized, O(log n) for LFU) and sharded concurrency (up to 16 shards for entry-bounded caches) ship under the same public surface. Future internal improvements within the 1.x line will be source-compatible.
Documentation
- API Reference — every public item, with signature, contract, and code examples.
- Stability promise — frozen 1.0 surface + SemVer commitments.
- Docs index — release archive + quick links.
- CHANGELOG — per-version diff log.
- REPS standards — quality discipline this crate is held to.
- Machine-rendered rustdoc: docs.rs/cache-mod.
Standards
- REPS governs every decision. See REPS.md.
- MSRV: Rust 1.75.
- Edition: 2021.
- Cross-platform: Linux, macOS, Windows.
License
Dual-licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.