Skip to main content

CacheEntryAccess

Trait CacheEntryAccess 

Source
pub trait CacheEntryAccess<Key, Value>: Cache {
    // Required methods
    fn read(&self, key: &Key) -> Option<Value>;
    fn compute(&mut self, key: &Key) -> Value;
}
Expand description

Trait for Cachees that are internally a list of key-value pairs that are computed once and can be trivially returned without holding the lock.

Implementing this is required for crate::Memoizers::read_or_compute.

If computing a value needs data beyond the persistent cache key, use an accessor type for Key that contains both the stable key and borrowed inputs for the miss path. Self::read should only use the stable key, while Self::compute may use the additional inputs.

Required Methods§

Source

fn read(&self, key: &Key) -> Option<Value>

Reads the cache entry for the given key, if it exists.

Source

fn compute(&mut self, key: &Key) -> Value

Computes the cache entry for the given key and returns it.

crate::Memoizers::read_or_compute calls this while holding the cache’s write lock after checking the key a second time, so concurrent misses are guaranteed not to repeat the computation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§