CacheAccessor

Trait CacheAccessor 

Source
pub trait CacheAccessor<K, V>: Send + Sync {
    type Extra: Clone;

    // Required methods
    fn get(&self, k: &K) -> Option<V>;
    fn get_with_extra(&self, k: &K, e: &Self::Extra) -> Option<V>;
    fn put(&self, key: &K, value: V) -> Option<V>;
    fn put_with_extra(&self, key: &K, value: V, e: &Self::Extra) -> Option<V>;
    fn remove(&self, k: &K) -> Option<V>;
    fn contains_key(&self, k: &K) -> bool;
    fn len(&self) -> usize;
    fn clear(&self);
    fn name(&self) -> String;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait that can be implemented to provide custom cache behavior for the caches managed by cache_manager::CacheManager.

Implementations must handle their own locking via internal mutability, as methods do not take mutable references and may be accessed by multiple concurrent queries.

Required Associated Types§

Required Methods§

Source

fn get(&self, k: &K) -> Option<V>

Get value from cache.

Source

fn get_with_extra(&self, k: &K, e: &Self::Extra) -> Option<V>

Get value from cache.

Source

fn put(&self, key: &K, value: V) -> Option<V>

Put value into cache. Returns the old value associated with the key if there was one.

Source

fn put_with_extra(&self, key: &K, value: V, e: &Self::Extra) -> Option<V>

Put value into cache. Returns the old value associated with the key if there was one.

Source

fn remove(&self, k: &K) -> Option<V>

Remove an entry from the cache, returning value if they existed in the map.

Source

fn contains_key(&self, k: &K) -> bool

Check if the cache contains a specific key.

Source

fn len(&self) -> usize

Fetch the total number of cache entries.

Source

fn clear(&self)

Remove all entries from the cache.

Source

fn name(&self) -> String

Return the cache name.

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the Cache collection is empty or not.

Implementors§