Struct rofl::cache::ThreadSafeCache
[−]
[src]
pub struct ThreadSafeCache<K, V, S = RandomState> where
K: Eq + Hash,
S: BuildHasher, { /* fields omitted */ }
A thread-safe cache of keys & cached values.
Actual values stored in the cache are Arc<V>'
s.
This is a wrapper around LruCache
that also counts various cache statistics,
like cache hits or cache misses.
Methods
impl<K: Eq + Hash, V> ThreadSafeCache<K, V>
[src]
impl<K, V, S> ThreadSafeCache<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
fn with_hasher(capacity: usize, hasher: S) -> Self
Create the cache with custom hasher and given capacity.
impl<K: Eq + Hash, V> ThreadSafeCache<K, V>
[src]
fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Eq + Hash,
K: Borrow<Q>,
Q: Eq + Hash,
Check if the cache contains given key.
fn get<Q: ?Sized>(&self, key: &Q) -> Option<Arc<V>> where
K: Borrow<Q>,
Q: Eq + Hash,
K: Borrow<Q>,
Q: Eq + Hash,
Get the element corresponding to given key if it's present in the cache.
fn put(&self, k: K, v: V) -> Arc<V>
Put an item into cache under given key.
This is like insert(), except it always returns the (Arc
'd) value
that's under the cached key.
If it wasn't there before, it will be the new value just inserted (i.e. v
).
fn insert(&self, k: K, v: V) -> Option<Arc<V>>
Insert an item into the cache under given key.
If the key is already present in the cache, returns its corresponding value.
fn remove<Q: ?Sized>(&self, key: &Q) -> Option<Arc<V>> where
K: Borrow<Q>,
Q: Eq + Hash,
K: Borrow<Q>,
Q: Eq + Hash,
Removes a key from the cache, if present, and returns its value.
fn capacity(&self) -> usize
Cache capacity.
fn set_capacity(&self, capacity: usize)
Set the capacity of the cache.
If the new capacity is smaller than current size of the cache, elements will be removed from it in the LRU manner.
fn remove_lru(&self) -> Option<(K, Arc<V>)>
Remove the least recently used element from the cache.
fn len(&self) -> usize
Current size of the cache.
fn is_empty(&self) -> bool
Whether the cache is empty.
fn clear(&self)
Remove all elements from the cache.
impl<K: Eq + Hash, V> ThreadSafeCache<K, V>
[src]
fn hits(&self) -> usize
Returns the number of cache hits.
fn misses(&self) -> usize
Returns the number of cache misses.