pub struct LruCache<K, V, S = RandomState> { /* private fields */ }Expand description
A weighted, thread-safe LRU cache.
Implementations§
Source§impl<K, V, S> LruCache<K, V, S>
impl<K, V, S> LruCache<K, V, S>
Sourcepub const DEFAULT_SHARDS: usize = 1
pub const DEFAULT_SHARDS: usize = 1
Default shard count reported by LruCache::shard_count.
Source§impl<K, V> LruCache<K, V, RandomState>
impl<K, V> LruCache<K, V, RandomState>
Source§impl<K, V, S> LruCache<K, V, S>
impl<K, V, S> LruCache<K, V, S>
Sourcepub fn with_hasher(max_cost: usize, _hash_builder: S) -> Self
pub fn with_hasher(max_cost: usize, _hash_builder: S) -> Self
Creates a cache with an explicit hash builder.
Sourcepub fn remove(&self, key: &K) -> Option<V>
pub fn remove(&self, key: &K) -> Option<V>
Removes key if present and returns the removed value.
Sourcepub fn remove_range<R>(&self, range: R) -> usizewhere
R: RangeBounds<K>,
pub fn remove_range<R>(&self, range: R) -> usizewhere
R: RangeBounds<K>,
Removes every entry whose key falls within range.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if key is currently resident.
Sourcepub fn total_charge(&self) -> usize
pub fn total_charge(&self) -> usize
Returns the total resident cost.
Sourcepub fn total_capacity(&self) -> usize
pub fn total_capacity(&self) -> usize
Returns the configured total cost capacity.
Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
Returns the number of shards reported by this backend.
Trait Implementations§
Source§impl<K, V, S> BufferCache<K, V> for LruCache<K, V, S>
impl<K, V, S> BufferCache<K, V> for LruCache<K, V, S>
Source§fn strategy(&self) -> BufferCacheStrategy
fn strategy(&self) -> BufferCacheStrategy
Returns the eviction strategy used by this cache.
Source§fn remove(&self, key: &K) -> Option<V>
fn remove(&self, key: &K) -> Option<V>
Removes
key if it is present and returns the removed value.Source§fn remove_if(&self, predicate: &dyn Fn(&K) -> bool)
fn remove_if(&self, predicate: &dyn Fn(&K) -> bool)
Removes every entry whose key matches
predicate.Source§fn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
Returns
true if key is currently resident.Source§fn total_charge(&self) -> usize
fn total_charge(&self) -> usize
Returns the total resident weight.
Source§fn total_capacity(&self) -> usize
fn total_capacity(&self) -> usize
Returns the configured total weight capacity.
Source§fn shard_count(&self) -> usize
fn shard_count(&self) -> usize
Returns the number of shards used by this backend.
Auto Trait Implementations§
impl<K, V, S = RandomState> !Freeze for LruCache<K, V, S>
impl<K, V, S> RefUnwindSafe for LruCache<K, V, S>
impl<K, V, S> Send for LruCache<K, V, S>
impl<K, V, S> Sync for LruCache<K, V, S>
impl<K, V, S> Unpin for LruCache<K, V, S>
impl<K, V, S> UnsafeUnpin for LruCache<K, V, S>
impl<K, V, S> UnwindSafe for LruCache<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