pub struct LookupCache { /* private fields */ }Expand description
TTL-based CID → providers cache for DHT lookups.
Implementations§
Source§impl LookupCache
impl LookupCache
Sourcepub fn new(config: LookupCacheConfig) -> Arc<Self> ⓘ
pub fn new(config: LookupCacheConfig) -> Arc<Self> ⓘ
Create a new LookupCache wrapped in an Arc.
Sourcepub fn get(&self, cid_str: &str, now_ms: u64) -> Option<Vec<String>>
pub fn get(&self, cid_str: &str, now_ms: u64) -> Option<Vec<String>>
Look up providers for a CID.
Returns None on a cache miss or when the entry has expired.
On a hit the hit_count for the entry is incremented and the
provider list is returned.
Sourcepub fn put(
&self,
cid_str: impl Into<String>,
providers: Vec<String>,
now_ms: u64,
)
pub fn put( &self, cid_str: impl Into<String>, providers: Vec<String>, now_ms: u64, )
Store a positive result (providers found) for cid_str.
If the cache is at capacity the new entry still replaces any existing
entry for the same CID; overall capacity enforcement is left to
evict_expired.
Sourcepub fn put_negative(&self, cid_str: impl Into<String>, now_ms: u64)
pub fn put_negative(&self, cid_str: impl Into<String>, now_ms: u64)
Store a negative result (no providers found) for cid_str.
Negative entries use LookupCacheConfig::negative_ttl_ms as TTL and
an empty provider list.
Sourcepub fn invalidate(&self, cid_str: &str) -> bool
pub fn invalidate(&self, cid_str: &str) -> bool
Invalidate the entry for cid_str.
Returns true if an entry existed and was removed.
Sourcepub fn evict_expired(&self, now_ms: u64) -> usize
pub fn evict_expired(&self, now_ms: u64) -> usize
Remove all expired entries.
Returns the number of entries removed.
Sourcepub fn stats(&self) -> LookupCacheStats
pub fn stats(&self) -> LookupCacheStats
Return a snapshot of current cache statistics.
Auto Trait Implementations§
impl !Freeze for LookupCache
impl !RefUnwindSafe for LookupCache
impl Send for LookupCache
impl Sync for LookupCache
impl Unpin for LookupCache
impl UnsafeUnpin for LookupCache
impl UnwindSafe for LookupCache
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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