pub struct Cache<K, V, S = RandomState> { /* private fields */ }
Expand description
Highly performant, thread-safe cache with a focus on simplicity.
It implements the S3-FIFO eviction algorithm as specified in FIFO Queues are All You Need for Cache Eviction. The cache is divided into multiple shards to reduce contention during concurrent access. This crate does not use any unsafe code.
Wrap the cache in a std::sync::Arc
to share it between threads. Both reads and writes only
require shared references to the cache.
Implementations§
Source§impl<K, V> Cache<K, V, RandomState>
impl<K, V> Cache<K, V, RandomState>
Sourcepub fn with_capacity(capacity: usize) -> Cache<K, V, RandomState>
pub fn with_capacity(capacity: usize) -> Cache<K, V, RandomState>
Creates a new cache with at least the specified capacity.
The actual capacity may be slightly higher due to sharding and rounding.
Source§impl<K, V, S> Cache<K, V, S>
impl<K, V, S> Cache<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for Cache<K, V, S>where
S: Freeze,
impl<K, V, S = RandomState> !RefUnwindSafe for Cache<K, V, S>
impl<K, V, S> Send for Cache<K, V, S>
impl<K, V, S> Sync for Cache<K, V, S>
impl<K, V, S> Unpin for Cache<K, V, S>
impl<K, V, S> UnwindSafe for Cache<K, V, S>
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