pub struct ContentAddressedCacheV2 { /* private fields */ }Expand description
Production-grade content-addressed cache with hot/warm tiering, Bloom-filter admission control, and rich eviction accounting.
Implementations§
Source§impl ContentAddressedCacheV2
impl ContentAddressedCacheV2
Sourcepub fn new(config: Cac2CacheConfig) -> Self
pub fn new(config: Cac2CacheConfig) -> Self
Construct a new cache with the given configuration.
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Construct with default configuration.
Sourcepub fn bloom_probably_contains(&self, cid: &Cac2Cid) -> bool
pub fn bloom_probably_contains(&self, cid: &Cac2Cid) -> bool
Test whether cid probably exists in the admission filter.
Sourcepub fn insert(&mut self, cid: Cac2Cid, data: Vec<u8>)
pub fn insert(&mut self, cid: Cac2Cid, data: Vec<u8>)
Insert data under cid.
Admission control: if the Bloom filter does not contain cid yet
(i.e., this is a cold first-time access), the entry is written only to
the warm tier — bypassing the hot tier to protect it from one-hit
wonders. If the Bloom filter does contain the CID (repeat access),
the entry is routed to the hot tier directly.
Eviction cascade:
- Hot full → demote the LRU hot entry to warm.
- Warm full → evict the entry with the lowest
access_count(LFU).
Sourcepub fn get(&mut self, cid: &Cac2Cid) -> Option<&[u8]>
pub fn get(&mut self, cid: &Cac2Cid) -> Option<&[u8]>
Retrieve a cached payload.
Look-up order: hot tier first, then warm tier. A warm hit with
access_count > admission_threshold triggers promotion to the hot tier.
Sourcepub fn expire_stale(&mut self, now_ts: u64)
pub fn expire_stale(&mut self, now_ts: u64)
Remove all entries whose TTL has elapsed as of now_ts.
Pass now_secs() for the current wall-clock time.
Sourcepub fn drain_warm_to_disk_simulation(&mut self) -> Vec<(Cac2Cid, Vec<u8>)>
pub fn drain_warm_to_disk_simulation(&mut self) -> Vec<(Cac2Cid, Vec<u8>)>
Drain the lowest-frequency 25% of warm-tier entries, returning them
as (Cac2Cid, Vec<u8>) pairs so the caller can write them to disk.
This simulates a write-back flush in a hierarchical storage system.
Sourcepub fn cache_stats(&self) -> Cac2CacheStats
pub fn cache_stats(&self) -> Cac2CacheStats
Return a snapshot of the current cache statistics.
Sourcepub fn eviction_log(&self) -> &VecDeque<Cac2EvictionRecord>
pub fn eviction_log(&self) -> &VecDeque<Cac2EvictionRecord>
Expose a reference to the eviction log.
Sourcepub fn config(&self) -> &Cac2CacheConfig
pub fn config(&self) -> &Cac2CacheConfig
Return the current configuration.
Auto Trait Implementations§
impl Freeze for ContentAddressedCacheV2
impl RefUnwindSafe for ContentAddressedCacheV2
impl Send for ContentAddressedCacheV2
impl Sync for ContentAddressedCacheV2
impl Unpin for ContentAddressedCacheV2
impl UnsafeUnpin for ContentAddressedCacheV2
impl UnwindSafe for ContentAddressedCacheV2
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more