pub trait Cache {
type Arg;
type Output;
// Required methods
fn new() -> Self;
fn get(&self, arg: &Self::Arg) -> Option<Arc<OnceCell<Self::Output>>>;
fn get_or_new(&self, arg: Self::Arg) -> Arc<OnceCell<Self::Output>>;
fn clear(&self);
}
Expand description
The cache for synchronized memoization.
Required Associated Types§
Required Methods§
Sourcefn get(&self, arg: &Self::Arg) -> Option<Arc<OnceCell<Self::Output>>>
fn get(&self, arg: &Self::Arg) -> Option<Arc<OnceCell<Self::Output>>>
Gets the cell of the arg
in cache. Returns None
if arg
is not cached.
This method should only acquire read lock if needed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<Arg, Output> Cache for RwLock<HashMap<Arg, Arc<OnceCell<Output>>>>
Use HashMap
with RwLock
as Cache
.
impl<Arg, Output> Cache for RwLock<HashMap<Arg, Arc<OnceCell<Output>>>>
Use HashMap
with RwLock
as Cache
.
Source§impl<Output> Cache for RwLock<Vec<Arc<OnceCell<Output>>>>
Use Vec
with RwLock
as Cache
for sequences.
impl<Output> Cache for RwLock<Vec<Arc<OnceCell<Output>>>>
Use Vec
with RwLock
as Cache
for sequences.