Trait Cache

Source
pub trait Cache<K, V>:
    Debug
    + Send
    + Sync {
    // Required methods
    fn insert(&self, key: K, value: V) -> Box<dyn CacheEntry<V>>;
    fn get(&self, key: &K) -> Option<Box<dyn CacheEntry<V>>>;
    fn remove(&self, key: &K);
    fn new_id(&self) -> u64;
}
Expand description

A cache that stores mappings from keys to values.

§Concurrency

Implementations of this trait must be thread-safe.

Required Methods§

Source

fn insert(&self, key: K, value: V) -> Box<dyn CacheEntry<V>>

Insert the key-value pair into the cache.

If the key already existed in the cache, no update is performed.

Returns a CacheEntry for the inserted value.

Source

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

Get the cached value for the given key. Returns None if the key is not in the cache.

Source

fn remove(&self, key: &K)

Remove the cached value for the given key.

Source

fn new_id(&self) -> u64

A numeric ID for different clients of the cache.

A cache may be used by different clients that are sharing the same cache. This ID is used to partition the key space between the clients. Typically a client will allocate a new ID at startup and prepend the ID to its cache keys.

Implementors§

Source§

impl<K, V> Cache<K, V> for LRUCache<K, V>
where K: Clone + Hash + Eq + Debug + Send + Sync + 'static, V: Debug + Send + Sync + 'static,