pub trait BufferCache<K, V>:
Any
+ Send
+ Sync {
// Required methods
fn as_any(&self) -> &dyn Any;
fn strategy(&self) -> BufferCacheStrategy;
fn insert(&self, key: K, value: V);
fn get(&self, key: K) -> Option<V>;
fn remove(&self, key: &K) -> Option<V>;
fn remove_if(&self, predicate: &dyn Fn(&K) -> bool);
fn contains_key(&self, key: &K) -> bool;
fn len(&self) -> usize;
fn total_charge(&self) -> usize;
fn total_capacity(&self) -> usize;
fn shard_count(&self) -> usize;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
Common object-safe API implemented by all buffer-cache backends.
Required Methods§
Sourcefn strategy(&self) -> BufferCacheStrategy
fn strategy(&self) -> BufferCacheStrategy
Returns the eviction strategy used by this cache.
Sourcefn insert(&self, key: K, value: V)
fn insert(&self, key: K, value: V)
Inserts or replaces key with value.
When a key, value is inserted with a the cost that exceeds the capacity of a shard in the cache, it is up to the implementation to decided if it wants to store/accept the key, value pair.
Sourcefn remove(&self, key: &K) -> Option<V>
fn remove(&self, key: &K) -> Option<V>
Removes key if it is present and returns the removed value.
Sourcefn remove_if(&self, predicate: &dyn Fn(&K) -> bool)
fn remove_if(&self, predicate: &dyn Fn(&K) -> bool)
Removes every entry whose key matches predicate.
Sourcefn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
Returns true if key is currently resident.
Sourcefn total_charge(&self) -> usize
fn total_charge(&self) -> usize
Returns the total resident weight.
Sourcefn total_capacity(&self) -> usize
fn total_capacity(&self) -> usize
Returns the configured total weight capacity.
Sourcefn shard_count(&self) -> usize
fn shard_count(&self) -> usize
Returns the number of shards used by this backend.