pub struct LocalCache<T> { /* private fields */ }Expand description
A cache that can store only a single type.
It is internally reference counted, so cloning it is cheap.
Implementations§
Source§impl<T> LocalCache<T>
impl<T> LocalCache<T>
Sourcepub async fn is_cached_async(&self, path: impl AsRef<str>) -> bool
pub async fn is_cached_async(&self, path: impl AsRef<str>) -> bool
Checks if a value exists in the cache. Waiting is done asynchronously.
Sourcepub fn get(&self, path: impl AsRef<str>) -> Option<Arc<T>>
pub fn get(&self, path: impl AsRef<str>) -> Option<Arc<T>>
Obtains a value from the cache, if it exists.
Sourcepub async fn get_async(&self, path: impl AsRef<str>) -> Option<Arc<T>>
pub async fn get_async(&self, path: impl AsRef<str>) -> Option<Arc<T>>
Obtains a value from the cache, if it exists. Waiting is done asynchronously.
Sourcepub fn get_or(&self, path: impl AsRef<str>, default: Arc<T>) -> Arc<T>
pub fn get_or(&self, path: impl AsRef<str>, default: Arc<T>) -> Arc<T>
Obtains a value from the cache, or adds default if it does not exist.
Sourcepub async fn get_or_async(
&self,
path: impl AsRef<str>,
default: Arc<T>,
) -> Arc<T>
pub async fn get_or_async( &self, path: impl AsRef<str>, default: Arc<T>, ) -> Arc<T>
Obtains a value from the cache, or adds default if it does not exist. Waiting is done
asynchronously.
Sourcepub fn get_or_else<F: FnOnce() -> Arc<T>>(
&self,
path: impl AsRef<str>,
f: F,
) -> Arc<T>
pub fn get_or_else<F: FnOnce() -> Arc<T>>( &self, path: impl AsRef<str>, f: F, ) -> Arc<T>
Obtains a value from the cache, or loads it from a closure if it does not exist.
Sourcepub async fn get_or_else_async<F: AsyncFnOnce() -> Arc<T>>(
&self,
path: impl AsRef<str>,
f: F,
) -> Arc<T>
pub async fn get_or_else_async<F: AsyncFnOnce() -> Arc<T>>( &self, path: impl AsRef<str>, f: F, ) -> Arc<T>
Similar to get_or_else, but for async closures.
Unlike the non-async variants, this not an atomic operation. Your closure may be run more than once, but only the first run will write to the cache.
Sourcepub fn get_or_else_try<F>(&self, path: impl AsRef<str>, f: F) -> Option<Arc<T>>
pub fn get_or_else_try<F>(&self, path: impl AsRef<str>, f: F) -> Option<Arc<T>>
Similar to get_or_else, but allows the closure to return None, in which case the
value is not added to the cache and None is returned.
Sourcepub async fn get_or_else_try_async<F: AsyncFnOnce() -> Option<Arc<T>>>(
&self,
path: impl AsRef<str>,
f: F,
) -> Option<Arc<T>>
pub async fn get_or_else_try_async<F: AsyncFnOnce() -> Option<Arc<T>>>( &self, path: impl AsRef<str>, f: F, ) -> Option<Arc<T>>
Similar to get_or_else_async, but allows the closure to return None, in which case
the value is not added to the cache and None is returned.
Unlike the non-async variants, this not an atomic operation. Your closure may be run more than once, but only the first run will write to the cache.
Trait Implementations§
Source§impl<T: Clone> Clone for LocalCache<T>
impl<T: Clone> Clone for LocalCache<T>
Source§fn clone(&self) -> LocalCache<T>
fn clone(&self) -> LocalCache<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more