[−][src]Struct ccl::timedcache::TimedCache
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]
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
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,
K: Send,
V: Send,
impl<K, V> Sync for TimedCache<K, V> where
K: Send + Sync,
V: Send + Sync,
K: Send + Sync,
V: Send + Sync,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,