[][src]Struct ccl::timedcache::TimedCache

pub struct TimedCache<K, V> where
    K: Hash + Eq + Clone
{ /* fields omitted */ }

Threadsafe concurrent timed cache. Handles loading and potential saving behind the scenes with user supplied functions. Intended for use in high concurrency applications.

The do_check method has to be called periodically to do maintenance. The supplied durations ensure that maintenance is done independently of how often do_check is called.

Methods

impl<'a, K: Hash + Eq + Clone, V> TimedCache<K, V>[src]

pub fn new(
    load_item: fn(_: &K) -> Option<V>,
    save_item: fn(_: &K, _: &V) -> bool,
    valid_duration: Option<Duration>,
    valid_check_interval: Option<Duration>,
    save_interval: Option<Duration>
) -> Self
[src]

Creates a new TimedCache. Saving function may be empty if no custom saving functionality is needed. Takes three duration arguments. Supply None to use the defaults.

The valid_duration argument specifies how long a entry is valid before scheduling it for eviction.

The valid_check_interval argument specifies how often expiry checking is done.

The save_interval argument specifies how often to call the save function on unsaved entries.

pub fn load_item(&self, k: &K)[src]

Load an item with a specified key. Intended to mainly be called from map and map_mut

pub fn map<T, F: FnOnce(&V) -> T>(&self, k: &K, f: F) -> T[src]

Takes a closure with a normal reference as an argument and executes it. The function will return the same value as the closure which means the function can be used to extract data.

pub fn map_mut<T, F: FnOnce(&mut V) -> T>(&self, k: &K, f: F) -> T[src]

Takes a closure with a mutable reference as an argument and executes it. The function will return the same value as the closure which means the function can be used to extract data.

pub fn save_all(&self)[src]

Saves all entries. Useful to run before shutting down gracefully.

pub fn do_check(&self)[src]

Performs maintenance tasks like saving and evicting invalid entries. May take significant time depending on amount of entries and the time complexity of saving each. This is intended to be improved in a future iteration of TimedCache.

Auto Trait Implementations

impl<K, V> Send for TimedCache<K, V> where
    K: Send,
    V: Send

impl<K, V> Sync for TimedCache<K, V> where
    K: Send + Sync,
    V: Send + Sync

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]