[][src]Trait cached::Cached

pub trait Cached<K, V> {
    fn cache_get(&mut self, k: &K) -> Option<&V>;
fn cache_get_mut(&mut self, k: &K) -> Option<&mut V>;
fn cache_set(&mut self, k: K, v: V) -> Option<V>;
fn cache_get_or_set_with<F: FnOnce() -> V>(&mut self, k: K, f: F) -> &mut V;
fn cache_remove(&mut self, k: &K) -> Option<V>;
fn cache_clear(&mut self);
fn cache_reset(&mut self);
fn cache_size(&self) -> usize; fn cache_hits(&self) -> Option<u64> { ... }
fn cache_misses(&self) -> Option<u64> { ... }
fn cache_capacity(&self) -> Option<usize> { ... }
fn cache_lifespan(&self) -> Option<u64> { ... }
fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64> { ... } }

Cache operations

Required methods

fn cache_get(&mut self, k: &K) -> Option<&V>

Attempt to retrieve a cached value

fn cache_get_mut(&mut self, k: &K) -> Option<&mut V>

Attempt to retrieve a cached value with mutable access

fn cache_set(&mut self, k: K, v: V) -> Option<V>

Insert a key, value pair and return the previous value

fn cache_get_or_set_with<F: FnOnce() -> V>(&mut self, k: K, f: F) -> &mut V

Get or insert a key, value pair

fn cache_remove(&mut self, k: &K) -> Option<V>

Remove a cached value

fn cache_clear(&mut self)

Remove all cached values. Keeps the allocated memory for reuse.

fn cache_reset(&mut self)

Remove all cached values. Free memory and return to initial state

fn cache_size(&self) -> usize

Return the current cache size (number of elements)

Loading content...

Provided methods

fn cache_hits(&self) -> Option<u64>

Return the number of times a cached value was successfully retrieved

fn cache_misses(&self) -> Option<u64>

Return the number of times a cached value was unable to be retrieved

fn cache_capacity(&self) -> Option<usize>

Return the cache capacity

fn cache_lifespan(&self) -> Option<u64>

Return the lifespan of cached values (time to eviction)

fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64>

Set the lifespan of cached values, returns the old value

Loading content...

Implementations on Foreign Types

impl<K: Hash + Eq, V> Cached<K, V> for HashMap<K, V>[src]

Loading content...

Implementors

impl<K: Hash + Eq + Clone, V> Cached<K, V> for SizedCache<K, V>[src]

impl<K: Hash + Eq, V> Cached<K, V> for TimedCache<K, V>[src]

impl<K: Hash + Eq, V> Cached<K, V> for UnboundCache<K, V>[src]

Loading content...