pub struct Cache<T> { /* private fields */ }
Expand description
This is a lock-free concurrent cache. It stores only the most up-to-date value.
Implementations§
Source§impl<T> Cache<T>
impl<T> Cache<T>
pub fn new(value: T, version: usize) -> Self
Sourcepub fn value(
&self,
version: usize,
f: impl FnOnce() -> T,
) -> Result<CacheValueType<T>, impl FnOnce() -> T>
pub fn value( &self, version: usize, f: impl FnOnce() -> T, ) -> Result<CacheValueType<T>, impl FnOnce() -> T>
Tries to retrieve value for the specified version. Returns a result either containing a cached value, or an f (which is guaranteed to be not invoked by function call in this case). If requested version corresponds to the value currently stored in cache - the value is returned. If requested version is older None will be returned. If requested version is newer, the new value will be computed and stored by calling f, and then returned, unless the value is being currently updated - in this case None will be returned. If None is returned it is guaranteed that f was not called.
Auto Trait Implementations§
impl<T> !Freeze for Cache<T>
impl<T> RefUnwindSafe for Cache<T>where
T: RefUnwindSafe,
impl<T> Send for Cache<T>
impl<T> Sync for Cache<T>
impl<T> Unpin for Cache<T>
impl<T> UnwindSafe for Cache<T>where
T: RefUnwindSafe,
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