Struct TimedCache

Source
pub struct TimedCache<Key: Hash + Eq + Clone, Value> { /* private fields */ }
Expand description

A collection which stores a value for a set amount of time.

Each stored value will keep track of when it was stored, and once the value has been considered valid for the specified length of time, it will be re-generated using the generator function provided when attempting to retrieve a value using TimedCache::get.

Implementations§

Source§

impl<Key: Hash + Eq + Clone, Value> TimedCache<Key, Value>

Source

pub fn with_time_to_keep(time_to_keep: Duration) -> TimedCache<Key, Value>

Creates a TimedCache with the specified Duration as the length of time the values will be considered ‘valid’ after initial storage.

Source

pub fn get(&mut self, key: &Key, generate_value: impl Fn() -> Value) -> &Value

Retrieves a reference to the value stored in the cache for the key if it exists and is still considered valid, otherwise calls generate_value to generate the value to store in the cache and returns a reference to that value.

Auto Trait Implementations§

§

impl<Key, Value> Freeze for TimedCache<Key, Value>

§

impl<Key, Value> RefUnwindSafe for TimedCache<Key, Value>
where Key: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<Key, Value> Send for TimedCache<Key, Value>
where Key: Send, Value: Send,

§

impl<Key, Value> Sync for TimedCache<Key, Value>
where Key: Sync, Value: Sync,

§

impl<Key, Value> Unpin for TimedCache<Key, Value>
where Key: Unpin, Value: Unpin,

§

impl<Key, Value> UnwindSafe for TimedCache<Key, Value>
where Key: UnwindSafe, Value: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.