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.
Required Methods§
Sourcefn read(&self, key: &Key) -> Option<Value>
fn read(&self, key: &Key) -> Option<Value>
Reads the cache entry for the given key, if it exists.
Sourcefn compute(&mut self, key: &Key) -> Value
fn compute(&mut self, key: &Key) -> Value
Computes the cache entry for the given key and returns it.
While we generally expect this to be called only ever once for a given key, in high contended situations it may be called repeatedly for the same key. Implementations have to handle this gracefully.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".