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§
Sourcefn get_with_extra(&self, k: &K, e: &Self::Extra) -> Option<V>
fn get_with_extra(&self, k: &K, e: &Self::Extra) -> Option<V>
Get value from cache.
Sourcefn put(&self, key: &K, value: V) -> Option<V>
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.
Sourcefn put_with_extra(&self, key: &K, value: V, e: &Self::Extra) -> Option<V>
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.
Sourcefn remove(&self, k: &K) -> Option<V>
fn remove(&self, k: &K) -> Option<V>
Remove an entry from the cache, returning value if they existed in the map.
Sourcefn contains_key(&self, k: &K) -> bool
fn contains_key(&self, k: &K) -> bool
Check if the cache contains a specific key.