Cache

Trait Cache 

Source
pub trait Cache<K: Hash + Eq, V> {
    // Required methods
    fn put(&mut self, k: K, v: V) -> PutResult<K, V>;
    fn get<Q>(&mut self, k: &Q) -> Option<&V>
       where K: Borrow<Q>,
             Q: Hash + Eq + ?Sized;
    fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
       where K: Borrow<Q>,
             Q: Hash + Eq + ?Sized;
    fn peek<Q>(&self, k: &Q) -> Option<&V>
       where K: Borrow<Q>,
             Q: Hash + Eq + ?Sized;
    fn peek_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
       where K: Borrow<Q>,
             Q: Hash + Eq + ?Sized;
    fn contains<Q>(&self, k: &Q) -> bool
       where K: Borrow<Q>,
             Q: Hash + Eq + ?Sized;
    fn remove<Q>(&mut self, k: &Q) -> Option<V>
       where K: Borrow<Q>,
             Q: Hash + Eq + ?Sized;
    fn purge(&mut self);
    fn len(&self) -> usize;
    fn cap(&self) -> usize;
    fn is_empty(&self) -> bool;
}
Expand description

Cache contains the basic APIs for a cache. All of caches in this crate implement this trait.

Required Methods§

Source

fn put(&mut self, k: K, v: V) -> PutResult<K, V>

Puts a key-value pair into cache, returns a PutResult.

Source

fn get<Q>(&mut self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the value of the key in the cache or None if it is not present in the cache. Update the cache if it exists.

Source

fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a mutable reference to the value of the key in the cache or None if it is not present in the cache. Update the cache if it exists.

Source

fn peek<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the value corresponding to the key in the cache or None if it is not present in the cache. Unlike get, peek does not update the cache so the key’s position will be unchanged.

Source

fn peek_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a mutable reference to the value corresponding to the key in the cache or None if it is not present in the cache. Unlike get_mut, peek_mut does not update the cache so the key’s position will be unchanged.

Source

fn contains<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a bool indicating whether the given key is in the cache. Does not update the cache.

Source

fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes and returns the value corresponding to the key from the cache or None if it does not exist.

Source

fn purge(&mut self)

Clears the contents of the cache.

Source

fn len(&self) -> usize

Returns the number of key-value pairs that are currently in the the cache.

Source

fn cap(&self) -> usize

Returns the maximum number of key-value pairs the cache can hold.

Source

fn is_empty(&self) -> bool

Returns a bool indicating whether the cache is empty or not.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<K: Hash + Eq, V, E: OnEvictCallback, S: BuildHasher> Cache<K, V> for RawLRU<K, V, E, S>

Source§

impl<K: Hash + Eq, V, FH: BuildHasher, RH: BuildHasher> Cache<K, V> for SegmentedCache<K, V, FH, RH>

Source§

impl<K: Hash + Eq, V, KH: KeyHasher<K>, FH: BuildHasher, RH: BuildHasher, WH: BuildHasher> Cache<K, V> for WTinyLFUCache<K, V, KH, FH, RH, WH>

Source§

impl<K: Hash + Eq, V, RH: BuildHasher, FH: BuildHasher, GH: BuildHasher> Cache<K, V> for TwoQueueCache<K, V, RH, FH, GH>

Source§

impl<K: Hash + Eq, V, RH: BuildHasher, REH: BuildHasher, FH: BuildHasher, FEH: BuildHasher> Cache<K, V> for AdaptiveCache<K, V, RH, REH, FH, FEH>