pub struct ProofCachingLayer { /* private fields */ }Expand description
An LFU-evicting, TTL-expiring cache for proof results.
The internal store is a plain Vec intentionally: the default capacity is
256 entries so linear scan overhead is negligible, and it avoids the
overhead of a hash-map for this small working set.
Implementations§
Source§impl ProofCachingLayer
impl ProofCachingLayer
Sourcepub fn new(config: ProofCacheConfig) -> Self
pub fn new(config: ProofCacheConfig) -> Self
Create a new caching layer with the supplied configuration.
Sourcepub fn lookup(
&mut self,
key: &ProofCacheKey,
now_secs: u64,
) -> Option<&CachedProof>
pub fn lookup( &mut self, key: &ProofCacheKey, now_secs: u64, ) -> Option<&CachedProof>
Look up a proof by key.
- Stale entries (TTL exceeded) are skipped and treated as misses.
- On a hit,
access_countandlast_accessed_secsof the entry are updated in place, andstats.hitsis incremented. - On a miss,
stats.missesis incremented.
Returns a shared reference into self.entries on success.
Sourcepub fn insert(&mut self, proof: CachedProof)
pub fn insert(&mut self, proof: CachedProof)
Insert a proof into the cache.
- If an entry with the same key already exists it is replaced.
- If the cache is at capacity, the entry with the lowest
access_countis evicted first (LFU policy), andstats.evictionsis incremented.
Sourcepub fn invalidate_kb_version(&mut self, old_version: u64)
pub fn invalidate_kb_version(&mut self, old_version: u64)
Remove all entries whose key.kb_version == old_version (when
invalidate_on_kb_change is true).
stats.invalidations is incremented by the number of entries removed.
Sourcepub fn evict_stale(&mut self, now_secs: u64) -> usize
pub fn evict_stale(&mut self, now_secs: u64) -> usize
Remove all stale entries and return the number removed.
Sourcepub fn stats(&self) -> &ProofCacheStats
pub fn stats(&self) -> &ProofCacheStats
Return a shared reference to the current statistics.
Trait Implementations§
Source§impl Debug for ProofCachingLayer
impl Debug for ProofCachingLayer
Auto Trait Implementations§
impl Freeze for ProofCachingLayer
impl RefUnwindSafe for ProofCachingLayer
impl Send for ProofCachingLayer
impl Sync for ProofCachingLayer
impl Unpin for ProofCachingLayer
impl UnsafeUnpin for ProofCachingLayer
impl UnwindSafe for ProofCachingLayer
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
Mutably borrows from an owned value. Read more
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>
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 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>
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