Expand description
64-shard query cache with three-tier invalidation.
Each shard is a parking_lot::RwLock<HashMap<QueryKey, CachedResult>>.
Sharding reduces lock contention: concurrent reads to different query types
never contend. The shard count is configurable (must be a power of two).
§PN3 raw-byte retention
For queries with PERSISTENT = true, ShardedCache::insert_query
serialises both the input key and the output value via postcard at insert
time and stores the raw bytes alongside the typed value. This makes
streaming the cache to disk in [iter_persistent] allocation-free after
the fact — no re-serialisation is needed during save.
Entries whose serialised size exceeds QueryDbConfig::max_entry_size_bytes
are not stored (soft skip — insert returns Ok(())). The caller’s
computed value is unaffected because QueryDb::get returns the value
directly without going through the cache for that invocation.
For PERSISTENT = false queries the raw bytes are set to empty slices and
[iter_persistent] skips them.
Structs§
- Cached
Result - A cached query result with dependency metadata for three-tier validation.
- Sharded
Cache - 64-shard query cache.