[][src]Trait fn_memo::sync::Cache

pub trait Cache {
    type Arg;
    type Output;
    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); }

The cache for synchronized memoization.

Associated Types

type Arg

type Output

Loading content...

Required methods

fn new() -> Self

Creates an empty cache.

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.

fn get_or_new(&self, arg: Self::Arg) -> Arc<OnceCell<Self::Output>>

Gets the cell of the arg in cache, creates if arg is not cached. This method can acquire write lock if needed.

fn clear(&self)

Clears the cache.

Loading content...

Implementations on Foreign Types

impl<Arg, Output> Cache for CHashMap<Arg, Arc<OnceCell<Output>>> where
    Arg: PartialEq + Hash
[src]

Use CHashMap as Cache.

type Arg = Arg

type Output = Output

impl<Arg, Output> Cache for RwLock<HashMap<Arg, Arc<OnceCell<Output>>>> where
    Arg: Eq + Hash
[src]

Use HashMap with RwLock as Cache.

type Arg = Arg

type Output = Output

impl<Output> Cache for RwLock<Vec<Arc<OnceCell<Output>>>>[src]

Use Vec with RwLock as Cache for sequences.

type Arg = usize

type Output = Output

Loading content...

Implementors

Loading content...