Skip to main content

ContentAddressedCacheV2

Struct ContentAddressedCacheV2 

Source
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

Source

pub fn new(config: Cac2CacheConfig) -> Self

Construct a new cache with the given configuration.

Source

pub fn default_config() -> Self

Construct with default configuration.

Source

pub fn bloom_probably_contains(&self, cid: &Cac2Cid) -> bool

Test whether cid probably exists in the admission filter.

Source

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:

  1. Hot full → demote the LRU hot entry to warm.
  2. Warm full → evict the entry with the lowest access_count (LFU).
Source

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.

Source

pub fn evict(&mut self, cid: &Cac2Cid)

Forcibly remove cid from all tiers.

Source

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.

Source

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.

Source

pub fn cache_stats(&self) -> Cac2CacheStats

Return a snapshot of the current cache statistics.

Source

pub fn eviction_log(&self) -> &VecDeque<Cac2EvictionRecord>

Expose a reference to the eviction log.

Source

pub fn config(&self) -> &Cac2CacheConfig

Return the current configuration.

Source

pub fn hot_len(&self) -> usize

Number of entries in the hot tier.

Source

pub fn warm_len(&self) -> usize

Number of entries in the warm tier.

Source

pub fn total_len(&self) -> usize

Total number of cached entries across both tiers.

Source

pub fn is_empty(&self) -> bool

Return true if neither tier contains any entry.

Source

pub fn contains(&self, cid: &Cac2Cid) -> bool

Check whether cid is present in either tier without updating stats.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more