pub struct TtlCache<K, V> { /* private fields */ }Expand description
Thread-safe cache with TTL (time-to-live) support for expensive computations
Implementations§
Source§impl<K, V> TtlCache<K, V>
impl<K, V> TtlCache<K, V>
Sourcepub fn get_or_compute<F>(&self, key: K, compute_fn: F) -> Vwhere
F: FnOnce() -> V,
pub fn get_or_compute<F>(&self, key: K, compute_fn: F) -> Vwhere
F: FnOnce() -> V,
Get or compute a value, caching the result
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Clear expired entries from the cache
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset cache statistics
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for TtlCache<K, V>
impl<K, V> RefUnwindSafe for TtlCache<K, V>
impl<K, V> Send for TtlCache<K, V>
impl<K, V> Sync for TtlCache<K, V>
impl<K, V> Unpin for TtlCache<K, V>
impl<K, V> UnsafeUnpin for TtlCache<K, V>
impl<K, V> UnwindSafe for TtlCache<K, V>
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