pub struct LruCache<K, V, T = AtomicInstant, S = DefaultHashBuilder> { /* private fields */ }Implementations§
Source§impl<K, V, T> LruCache<K, V, T, DefaultHashBuilder>
impl<K, V, T> LruCache<K, V, T, DefaultHashBuilder>
Source§impl<K, V, T, S> LruCache<K, V, T, S>
impl<K, V, T, S> LruCache<K, V, T, S>
pub fn with_hasher(num_shards: usize, hash_builder: S) -> Self
Source§impl<K, V, T, S> LruCache<K, V, T, S>
impl<K, V, T, S> LruCache<K, V, T, S>
pub fn size(&self) -> usize
pub fn hash_builder(&self) -> &S
pub fn num_shards(&self) -> usize
pub async fn retain<F>(&self, f: F)
pub async fn clear(&self)
pub async fn peek<Q>(&self, key: &Q) -> Option<ReadHandle<impl Erased, V>>
pub async fn peek_mut<Q>(&self, key: &Q) -> Option<WriteHandle<impl Erased, V>>
pub async fn get<Q>(&self, key: &Q) -> Option<ReadHandle<impl Erased, V>>
pub async fn get_mut<Q>(&self, key: &Q) -> Option<WriteHandle<impl Erased, V>>
pub async fn insert(&self, key: K, value: V) -> Option<V>
pub async fn remove<Q>(&self, key: &Q) -> Option<V>
Sourcepub async fn evict<F>(&self, rng: impl Rng, predicate: F) -> Vec<(K, V)>
pub async fn evict<F>(&self, rng: impl Rng, predicate: F) -> Vec<(K, V)>
Fair element eviction based on 2-random sampling of two shards at once, and performs a random walk through all shards as necessary to remain unbiased.
NOTE: This method acquires one write lock per element, and can be inefficient for many evictions.
If you want fair eviction of a handful of items, this is the method to use. For less-predictable bulk-eviction look at evict_many_fast
Sourcepub async fn evict_many(&self, count: usize, rng: impl Rng) -> Vec<(K, V)>
pub async fn evict_many(&self, count: usize, rng: impl Rng) -> Vec<(K, V)>
Fairly evict many elements, based on 2-random sampling of two shards at once, and performs a random walk through all shards as necessary to remain unbiased.
NOTE: This method acquires one write lock per element, and can be inefficient for many evictions.
If you want fair eviction of a handful of items, this is the method to use. For less-predictable bulk-eviction look at evict_many_fast
pub async fn evict_one(&self, rng: impl Rng) -> Option<(K, V)>
Sourcepub async fn evict_many_fast(&self, count: usize, rng: impl Rng) -> Vec<(K, V)>
pub async fn evict_many_fast(&self, count: usize, rng: impl Rng) -> Vec<(K, V)>
Less-fair and less-predictable algorithm that only acquires shard locks once at most, but may not evict the exact number of requested elements (a couple more or less)
Compare to evict or evict_many that acquires a shard lock per-item evicted,
but is more fair and unbiased in doing so.