pub struct TieredCache { /* private fields */ }Expand description
A multi-tier cache where each tier has its own TierConfig.
Reads check tiers in order (L1 first); a hit in tier i > 0 promotes the
entry to tier i-1 when the key’s access frequency in that tier meets or
exceeds the tier’s TierConfig::promotion_threshold. Writes always go
to L1 only.
Implementations§
Source§impl TieredCache
impl TieredCache
Sourcepub fn new(tiers: Vec<TierConfig>) -> Self
pub fn new(tiers: Vec<TierConfig>) -> Self
Construct a TieredCache from a list of tier configurations.
The first element is L1 (fastest / smallest), last is the slowest.
Sourcepub fn get(&mut self, key: &str) -> Option<Vec<u8>>
pub fn get(&mut self, key: &str) -> Option<Vec<u8>>
Look up key across all tiers in order.
On a hit in tier i > 0, the entry is promoted to tier i-1 if the key’s frequency in that tier meets or exceeds the effective promotion threshold (static or P²-adaptive depending on configuration).
Sourcepub fn put_at_tier(&mut self, tier_idx: usize, key: &str, data: Vec<u8>)
pub fn put_at_tier(&mut self, tier_idx: usize, key: &str, data: Vec<u8>)
Insert (key, data) directly into tier tier_idx.
Useful for pre-populating lower tiers (e.g. from a warm-up snapshot).
Sourcepub fn evict_tier(&mut self, tier_idx: usize) -> Option<(String, Vec<u8>)>
pub fn evict_tier(&mut self, tier_idx: usize) -> Option<(String, Vec<u8>)>
Evict one entry from tier tier_idx according to that tier’s policy.
Returns the evicted (key, data) or None if the tier is empty.
Sourcepub fn stats(&self) -> TieredCacheStats
pub fn stats(&self) -> TieredCacheStats
Return an aggregate statistics snapshot.
Sourcepub fn warmup(&mut self, entries: &[(String, Vec<u8>)])
pub fn warmup(&mut self, entries: &[(String, Vec<u8>)])
Bulk-insert entries into L1 without triggering eviction.
Sourcepub fn invalidate(&mut self, key: &str) -> bool
pub fn invalidate(&mut self, key: &str) -> bool
Remove key from every tier. Returns true if it was found in at
least one tier.
Sourcepub fn tier_count(&self) -> usize
pub fn tier_count(&self) -> usize
Return the number of tiers.
Sourcepub fn tier_promotions(&self, tier_idx: usize) -> u64
pub fn tier_promotions(&self, tier_idx: usize) -> u64
Return the number of promotions from tier tier_idx to the tier above.
Sourcepub fn tier_hit_count(&self, tier_idx: usize) -> u64
pub fn tier_hit_count(&self, tier_idx: usize) -> u64
Return the number of hits recorded for tier tier_idx.
Sourcepub fn reset_tier_arena(&mut self, tier_idx: usize)
pub fn reset_tier_arena(&mut self, tier_idx: usize)
Reset the bump arena of tier tier_idx (reclaims all arena memory).
After a reset, all previously stored arena handles for that tier are invalid; this is intended for use after a bulk eviction sweep.