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]

Create the cache with given capacity.

impl<K, V, S> ThreadSafeCache<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

Create the cache with custom hasher and given capacity.

impl<K: Eq + Hash, V> ThreadSafeCache<K, V>
[src]

Check if the cache contains given key.

Get the element corresponding to given key if it's present in the cache.

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).

Insert an item into the cache under given key.

If the key is already present in the cache, returns its corresponding value.

Removes a key from the cache, if present, and returns its value.

Cache capacity.

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.

Remove the least recently used element from the cache.

Current size of the cache.

Whether the cache is empty.

Remove all elements from the cache.

impl<K: Eq + Hash, V> ThreadSafeCache<K, V>
[src]

Returns the number of cache hits.

Returns the number of cache misses.

Trait Implementations

impl<K: Eq + Hash, V> Debug for ThreadSafeCache<K, V>
[src]

Formats the value using the given formatter.