Expand description
CacheStore — in-memory LRU + redb disk-backed cache.
§Architecture
get(key)
│
├─ validation gate: profile_validation_ts == None? → Ok(None)
│
├─ in-memory map hit? → deserialise + classify freshness → return
│
└─ redb table hit? → populate in-memory + classify freshness → returnput writes to both layers. invalidate removes from both layers.
invalidate_profile removes every key whose profile prefix matches.
§Disk schema
One redb table named "cache".
- Key : serialized
CacheKeybytes (CacheKey::serialize_key()). - Value:
serde_json::to_vec(CacheEntry<serde_json::Value>).
§Clock injection
CacheStore::new_with_clock accepts a Clock impl so tests can control
time without sleeping. Production code uses SystemClock.
Structs§
- Cache
Store - In-memory + disk-backed authoritative cache.
- InMemory
Entry 🔒 - An in-memory slot holds the raw JSON bytes so the type parameter can vary
per call site without making
CacheStoreitself generic. - Mock
Clock - Controllable test clock.
- System
Clock - Real wall-clock implementation.
Constants§
- CACHE_
TABLE 🔒 - Single table: serialized CacheKey → JSON-encoded
CacheEntry<Value>.
Traits§
- Clock
- Source of the current Unix timestamp in seconds.
Functions§
- open_
or_ recreate_ redb - Open a
redbDatabaseatpath, recreating the file when it has a stale on-disk schema. - open_
redb_ or_ in_ memory - Open a redb
Database, returning an in-memory backend as the final fallback so callers never have to panic during app startup.
Type Aliases§
- Cache
Handle - Shared cache handle. Clone to share across threads.