Trait il2_utils::cache::ValueCache[][src]

pub trait ValueCache<K: Eq + Hash + Copy + Sync, V: Send + Sync>: Send {
    fn get(&self, key: &K) -> Option<Arc<V>>;
fn insert(&self, key: K, value: &Arc<V>);
fn clear(&self);
fn len(&self) -> usize;
fn is_empty(&self) -> bool; }
Expand description

This trait is implemented by all value caches on this module. A value cache must be able to associate shared read-only values to a given key value.

It is up to the implementator of this trait to define how old values are prunned from the cache.

All methods of this trait are required to be thread safe.

Required methods

Gets the value from the cache if it exists.

Arguments:

  • key: The key to be found;

Returns:

  • Some(v): The cached value. v is a new Arc that points to it.
  • None: IF the entry is not in the cache;

Inserts the value into the cache. Reinserting a new value with the same key will replace the existing value.

Arguments:

  • key: The key;
  • value: A reference to an Arc that points to the value;

Removes all entries from the cache.

Returns the number of entries in the cache.

Returns true if the cache is empty or false otherwise.

Implementors