pub struct DecompressedChunkCache { /* private fields */ }Expand description
A shared, bytes-bounded, sharded decompressed-chunk cache.
Implementations§
Source§impl DecompressedChunkCache
impl DecompressedChunkCache
Sourcepub fn with_budget_bytes(total_budget_bytes: usize) -> Self
pub fn with_budget_bytes(total_budget_bytes: usize) -> Self
Create a cache with total_budget_bytes split across DEFAULT_SHARDS
shards.
Sourcepub fn with_budget_and_shards(
total_budget_bytes: usize,
shard_count: usize,
) -> Self
pub fn with_budget_and_shards( total_budget_bytes: usize, shard_count: usize, ) -> Self
Create a cache with total_budget_bytes split across shard_count shards.
shard_count is rounded UP to the next power of two (min 1) so shard
selection can mask instead of modulo. Unit tests use shard_count = 1 for
deterministic eviction ordering; production uses DEFAULT_SHARDS.
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
Create a genuine no-op cache (issue #1568): reads bypass it entirely.
Used when config.memory.block_cache.enabled == false so the advertised
toggle really disables caching instead of being decorative. get
always returns None (no counters touched), insert returns
the Arc without retaining it, and resident_bytes() / len() /
budget_bytes() all report 0. A single dummy shard is allocated only so
shard indexing stays valid; nothing is ever stored in it.
Sourcepub fn get(&self, key: &ChunkKey) -> Option<Bytes>
pub fn get(&self, key: &ChunkKey) -> Option<Bytes>
Look up a resident chunk. On a hit this bumps recency and returns a
Bytes::clone (refcount bump, no chunk-sized allocation). On a miss returns
None.
Sourcepub fn insert(&self, key: ChunkKey, data: Vec<u8>) -> Bytes
pub fn insert(&self, key: ChunkKey, data: Vec<u8>) -> Bytes
Insert data under key, returning the resident Bytes.
The Vec<u8> is converted to Bytes exactly once here via Bytes::from,
which is ZERO-COPY: it takes ownership of the Vec’s existing heap
allocation rather than allocating a new backing store and copying (issue
#1940 substrate). The returned handle and any subsequent get
share that one buffer (refcount-bumped clones). After insertion the owning
shard evicts LRU entries until it is within its byte budget (never evicting
the just-inserted entry).
Sourcepub fn resident_bytes(&self) -> usize
pub fn resident_bytes(&self) -> usize
Total resident decompressed bytes across all shards.
Sourcepub fn budget_bytes(&self) -> usize
pub fn budget_bytes(&self) -> usize
The configured total byte budget (budget_per_shard * shard count).
A disabled no-op cache reports 0 (it holds nothing).
Sourcepub fn miss_count(&self) -> u64
pub fn miss_count(&self) -> u64
Cumulative cache misses (test/observability instrumentation).
Sourcepub fn eviction_count(&self) -> u64
pub fn eviction_count(&self) -> u64
Cumulative entries evicted to stay within budget (issue #1571, B5).
Real relaxed-atomic counter; a disabled no-op cache
never evicts and reports 0.