Skip to main content

ContentRoutingCache

Struct ContentRoutingCache 

Source
pub struct ContentRoutingCache {
    pub config: CacheConfig,
    pub total_provider_lookups: u64,
    pub total_hint_lookups: u64,
    pub cache_hits: u64,
    pub cache_misses: u64,
    /* private fields */
}
Expand description

Multi-tier cache for DHT content routing.

Three independent tiers:

  1. Provider tier – stores CrcProviderRecords (multiple per CID).
  2. Hint tier – stores one RoutingHint per CID.
  3. Negative tier – stores one NegativeCacheEntry per CID.

Fields§

§config: CacheConfig

Cache configuration.

§total_provider_lookups: u64

Cumulative provider-tier lookup count.

§total_hint_lookups: u64

Cumulative hint-tier lookup count.

§cache_hits: u64

Cumulative cache hits (provider + hint tiers combined).

§cache_misses: u64

Cumulative cache misses (provider + hint tiers combined).

Implementations§

Source§

impl ContentRoutingCache

Source

pub fn new(config: CacheConfig) -> Self

Create a new cache with the given configuration.

Source

pub fn add_provider(&mut self, record: CrcProviderRecord)

Insert a provider record.

If the per-CID limit (MAX_PROVIDERS_PER_CID) would be exceeded the oldest record (smallest last_provided) is evicted first. If the global provider-CID limit would be exceeded the CID whose most-recent provider record is oldest is removed entirely.

Source

pub fn get_providers(&mut self, cid: &str, now: u64) -> Vec<&CrcProviderRecord>

Return all non-expired provider records for cid.

Expired records are removed in place. Updates lookup and hit/miss counters.

Source

pub fn remove_provider(&mut self, cid: &str, peer_id: &str) -> bool

Remove a specific provider record identified by (cid, peer_id).

Returns true if a record was removed.

Source

pub fn add_hint(&mut self, hint: RoutingHint)

Insert a routing hint.

If the hint-tier capacity would be exceeded the oldest hint (smallest cached_at) is evicted first.

Source

pub fn get_hint(&mut self, cid: &str, now: u64) -> Option<&RoutingHint>

Return the routing hint for cid if it exists and has not expired.

If the hint exists but is expired it is removed and None is returned. Updates lookup and hit/miss counters.

Source

pub fn remove_hint(&mut self, cid: &str) -> bool

Remove the hint for cid. Returns true if a hint was present.

Source

pub fn add_negative(&mut self, entry: NegativeCacheEntry)

Insert a negative cache entry.

If the negative-tier capacity would be exceeded the oldest entry (smallest not_found_at) is evicted first.

Source

pub fn is_negative(&mut self, cid: &str, now: u64) -> bool

Returns true if there is a live (non-expired) negative entry for cid.

If the entry is expired it is removed.

Source

pub fn remove_negative(&mut self, cid: &str) -> bool

Remove the negative entry for cid. Returns true if one existed.

Source

pub fn evict_expired(&mut self, now: u64) -> usize

Sweep all three tiers and remove expired entries.

Returns the total number of items removed.

Source

pub fn has_content(&self, cid: &str) -> bool

Returns true if the provider tier holds at least one record for cid.

Note: this does not check expiry; call evict_expired or get_providers to prune first if freshness matters.

Source

pub fn cache_stats(&self) -> CacheStats

Return a statistics snapshot.

Trait Implementations§

Source§

impl Debug for ContentRoutingCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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