pub struct TreeNodeCache { /* private fields */ }Expand description
In-process LRU cache of TreeNode postcard-encoded bytes.
Keyed by BLAKE3 hash; bytes-bounded eviction.
Caller wraps this in a Mutex for shared access. Single-
owner hot loops can use it unsynchronised.
Implementations§
Source§impl TreeNodeCache
impl TreeNodeCache
Sourcepub fn with_capacity_bytes(cap_bytes: usize) -> Self
pub fn with_capacity_bytes(cap_bytes: usize) -> Self
Construct a cache with an explicit byte cap. cap_bytes == 0 disables caching — every get misses, every
insert is a no-op. Useful for ablation testing or for
callers that want explicit cache disable.
Sourcepub fn get(&mut self, hash: &[u8; 32]) -> Option<Bytes>
pub fn get(&mut self, hash: &[u8; 32]) -> Option<Bytes>
Look up hash. On hit, returns a Bytes clone of the
cached entry (Bytes::clone is one atomic refcount bump,
not a memcpy of the node payload) and promotes the entry
to most-recently-used. On miss, returns None.
Sourcepub fn hit_ratio(&self) -> f64
pub fn hit_ratio(&self) -> f64
Hit ratio in [0.0, 1.0], or 0.0 when no accesses
have happened. Useful for operator dashboards.
Sourcepub fn remove(&mut self, hash: &[u8; 32])
pub fn remove(&mut self, hash: &[u8; 32])
Drop a single entry by hash. Used by the chunk-delete / GC sweep paths to keep the cache in sync with the on-disk chunk store: a manifest node whose chunk file just went away must not survive in cache, otherwise subsequent fetch_range walks descend through the cached node and only discover the missing chunks at the leaf, confusing operator error attribution. Cache integrity (bytes hash to key) is preserved either way — this fix is for error- path clarity, not for soundness.
No-op if the hash isn’t cached.