Cache is a cloneable handle created synchronously via Cache::builder()...open()?. Call get_or_fetch (or get_or_fetch_with_disk_fallthrough) with any borrowed Rust Hash key and an async callback that produces missing bytes. Each lookup records demand before checking either tier, even if it later fails or is canceled.
get checks memory and disk without a source callback. insert supplies immutable bytes synchronously without a runtime or recording lookup demand, inserting into memory and attempting a best-effort disk write enqueue.
The public boundary hashes Rust Hash inputs with SipHash-1-3-128 and a random secret 128-bit key per cache. Disk caches persist the key across reopens. Cloned handles share it. Both tiers and request history use only that 128-bit identity. Full keys are not stored or checked for collisions. Use cache.hash_key(&key) for matching application metadata.
- Check memory for the key hash.
- On a miss, join or start a shared in-flight fetch (keyed by object key hash and callback error type) that checks disk, verifies its checksum, and promotes to memory.
- On a disk miss (or disk-pressure fallthrough), run the source callback once for all shared waiters.
What happens after a successful fetch?
Optional admission filters (with_memory_admission_filter and with_disk_admission_filter) decide independently whether the payload enters each tier, receiving the key hash, payload length, and request history. Rejected fetches still return bytes to callers and keep demand in history.
Accepted payloads are stored in memory and queued for background disk writes without counting as another request. Memory filtering also runs on disk-hit promotions. Existing cached entries remain readable.