tiercache
A key-value cache over an ordered list of stores you bring: an in-process LRU, Redis, a database, anything that implements one small trait.
- get asks each level in order and stops at the first hit; the nearer levels are filled on the way back.
- put writes every level.
- delete removes the key from every level.
A failing level never fails a read: it counts as a miss, the next level is
asked, and the failure goes to your on_error hook. A failed delete is
returned, because a key left in one level would be served again.
No runtime, no dependency. The only store shipped is Lru (feature memory,
on by default, std only).
use ;
let cache = new
.on_error;
let hits = cache
.get_or_compute
.await?;
Bring a backend
use ;
Futures are boxed so stores of different types fit in one list. Keys are strings and values bytes; encoding is yours. There is no TTL in the trait: expiry belongs to the backend (Redis eviction, a database TTL policy), and keys that embed a version of what produced them never go stale.
A Cache is itself a CacheStore, so a list can contain another list.
License
MIT or Apache-2.0, at your option.