pub struct StatsCache<C> { /* private fields */ }Expand description
A cache wrapper that records hits and misses via CacheStats.
On each get call:
- If the inner cache returns
Some(v)→ hit recorded. - If the inner cache returns
None→ miss recorded.
§Type parameters
C: innerCache<Vec<u8>, Vec<u8>>implementation.
Implementations§
Source§impl<C> StatsCache<C>
impl<C> StatsCache<C>
Sourcepub fn with_stats(inner: C, stats: Arc<CacheStats>) -> Self
pub fn with_stats(inner: C, stats: Arc<CacheStats>) -> Self
Wrap inner with a shared CacheStats (useful for sharing across wrappers).
Sourcepub fn stats(&self) -> &Arc<CacheStats>
pub fn stats(&self) -> &Arc<CacheStats>
Return a reference to the underlying stats.
Trait Implementations§
Source§impl<C> Cache<Vec<u8>, Vec<u8>> for StatsCache<C>
impl<C> Cache<Vec<u8>, Vec<u8>> for StatsCache<C>
Source§fn get(&mut self, key: &Vec<u8>) -> Option<&Vec<u8>>
fn get(&mut self, key: &Vec<u8>) -> Option<&Vec<u8>>
Look up
key, returning a reference to the value if present. Read moreSource§fn put_with_ttl(
&mut self,
key: Vec<u8>,
value: Vec<u8>,
ttl: Duration,
) -> Option<Vec<u8>>
fn put_with_ttl( &mut self, key: Vec<u8>, value: Vec<u8>, ttl: Duration, ) -> Option<Vec<u8>>
Source§fn remove(&mut self, key: &Vec<u8>) -> Option<Vec<u8>>
fn remove(&mut self, key: &Vec<u8>) -> Option<Vec<u8>>
Remove the entry associated with
key, returning its value if present. Read moreSource§fn peek(&self, key: &Vec<u8>) -> Option<&Vec<u8>>
fn peek(&self, key: &Vec<u8>) -> Option<&Vec<u8>>
Look up
key without updating access metadata (no promotion). Read moreAuto Trait Implementations§
impl<C> Freeze for StatsCache<C>where
C: Freeze,
impl<C> RefUnwindSafe for StatsCache<C>where
C: RefUnwindSafe,
impl<C> Send for StatsCache<C>where
C: Send,
impl<C> Sync for StatsCache<C>where
C: Sync,
impl<C> Unpin for StatsCache<C>where
C: Unpin,
impl<C> UnsafeUnpin for StatsCache<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for StatsCache<C>where
C: UnwindSafe,
Blanket Implementations§
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