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>
impl<Key: Hash + Eq + Clone, Value> TimedCache<Key, Value>
Sourcepub fn with_time_to_keep(time_to_keep: Duration) -> TimedCache<Key, Value>
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.
Sourcepub fn get(&mut self, key: &Key, generate_value: impl Fn() -> Value) -> &Value
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>
impl<Key, Value> Sync for TimedCache<Key, Value>
impl<Key, Value> Unpin for TimedCache<Key, Value>
impl<Key, Value> UnwindSafe for TimedCache<Key, Value>where
Key: UnwindSafe,
Value: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more