pub struct TimedCache<Key: Hash + Eq + Clone, Value> { /* fields omitted */ }
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
.
Creates a TimedCache
with the specified Duration
as the length of time the values will
be considered 'valid' after initial storage.
pub fn get( &mut self, key: &Key, generate_value: impl Fn() -> Value ) -> &Value | [src] |
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.