Skip to main content

BufferCache

Trait BufferCache 

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

Source

fn as_any(&self) -> &dyn Any

Returns this backend as Any for backend-specific downcasts.

Source

fn strategy(&self) -> BufferCacheStrategy

Returns the eviction strategy used by this cache.

Source

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.

Source

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

Looks up key and returns a clone of the stored value.

Source

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

Removes key if it is present and returns the removed value.

Source

fn remove_if(&self, predicate: &dyn Fn(&K) -> bool)

Removes every entry whose key matches predicate.

Source

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

Returns true if key is currently resident.

Source

fn len(&self) -> usize

Returns the number of resident entries.

Source

fn total_charge(&self) -> usize

Returns the total resident weight.

Source

fn total_capacity(&self) -> usize

Returns the configured total weight capacity.

Source

fn shard_count(&self) -> usize

Returns the number of shards used by this backend.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the cache has no resident entries.

Implementors§

Source§

impl<K, V, S> BufferCache<K, V> for LruCache<K, V, S>
where K: Ord + Clone + Debug + Send + Sync + 'static, V: CacheEntry + Clone + Send + Sync + 'static, S: Send + Sync + 'static,

Source§

impl<K, V, S> BufferCache<K, V> for S3FifoCache<K, V, S>
where K: Eq + Hash + Clone + Send + Sync + 'static, V: CacheEntry + Clone + Send + Sync + 'static, S: BuildHasher + Clone + Send + Sync + 'static,