Trait CacheEngine

Source
pub trait CacheEngine<K: Eq + Hash + Copy + Sync, V: Send + Sync>: Sync {
    // Required methods
    fn get(&mut self, key: &K) -> Option<Arc<V>>;
    fn insert(&mut self, key: K, value: &Arc<V>);
    fn clear(&mut 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§

Source

fn get(&mut self, key: &K) -> Option<Arc<V>>

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;
Source

fn insert(&mut self, key: K, value: &Arc<V>)

Inserts the value into the cache.

Arguments:

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

fn clear(&mut self)

Removes all entries from the cache.

Source

fn len(&self) -> usize

Returns the number of entries in the cache.

Source

fn is_empty(&self) -> bool

Returns true if the cache is empty or false otherwise.

Implementors§