pub struct GlobalCache { /* private fields */ }Expand description
The shared, global cache, supporting dynamic typing. See the module-level docs for more info.
Implementations§
Source§impl GlobalCache
impl GlobalCache
Sourcepub fn is_cached(path: impl AsRef<str>) -> bool
pub fn is_cached(path: impl AsRef<str>) -> bool
Checks if a value exists in the global cache, regardless of type.
Sourcepub async fn is_cached_async(path: impl AsRef<str>) -> bool
pub async fn is_cached_async(path: impl AsRef<str>) -> bool
Checks if a value exists in the global cache, regardless of type, asynchronously.
Sourcepub fn is_cached_as<T: Any + Send + Sync>(path: impl AsRef<str>) -> bool
pub fn is_cached_as<T: Any + Send + Sync>(path: impl AsRef<str>) -> bool
Checks if a value exists in the global cache, is initialized, and is of the correct type.
Sourcepub async fn is_cached_as_async<T: Any + Send + Sync>(
path: impl AsRef<str>,
) -> bool
pub async fn is_cached_as_async<T: Any + Send + Sync>( path: impl AsRef<str>, ) -> bool
Checks if a value exists in the global cache, is initialized, and is of the correct type. Waits asynchronously.
Sourcepub fn get_dyn(path: impl AsRef<str>) -> Option<Arc<dyn Any + Send + Sync>>
pub fn get_dyn(path: impl AsRef<str>) -> Option<Arc<dyn Any + Send + Sync>>
Retrieves a value from the global cache, if it exists, without trying to downcast it.
Sourcepub async fn get_dyn_async(
path: impl AsRef<str>,
) -> Option<Arc<dyn Any + Send + Sync>>
pub async fn get_dyn_async( path: impl AsRef<str>, ) -> Option<Arc<dyn Any + Send + Sync>>
Retrieves a value from the global cache, if it exists, without trying to downcast it, asynchronously.
Sourcepub async fn get_async<T: Any + Send + Sync>(
path: impl AsRef<str>,
) -> Option<Arc<T>>
pub async fn get_async<T: Any + Send + Sync>( path: impl AsRef<str>, ) -> Option<Arc<T>>
Retrieves a value from the global cache, if it exists, asynchronously. Also returns
None if the cached value is of the wrong type.
If you wish to insert a default value, use get_or_async instead.
This is not suitable for async.
Sourcepub fn get_or<T: Any + Send + Sync>(
path: impl AsRef<str>,
default: Arc<T>,
) -> Option<Arc<T>>
pub fn get_or<T: Any + Send + Sync>( path: impl AsRef<str>, default: Arc<T>, ) -> Option<Arc<T>>
Retrieves a value from the global cache or adds default if it does not exist.
Also returns None if the cached value is of the wrong type.
This eagerly evaluates default even if the value already exists in the cache. It is
generally better to use get_or_else or one of its variants instead.
Sourcepub async fn get_or_async<T: Any + Send + Sync>(
path: impl AsRef<str>,
default: Arc<T>,
) -> Option<Arc<T>>
pub async fn get_or_async<T: Any + Send + Sync>( path: impl AsRef<str>, default: Arc<T>, ) -> Option<Arc<T>>
Retrieves a value from the global cache asynchronously or adds default if it does
not exist. Also returns None if the cached value is of the wrong type.
This eagerly evaluates default even if the value already exists in the cache. It is
generally better to use get_or_else_async or one of its variants instead.
Sourcepub fn get_or_else<T: Any + Send + Sync, F: FnOnce() -> Arc<T>>(
path: impl AsRef<str>,
f: F,
) -> Option<Arc<T>>
pub fn get_or_else<T: Any + Send + Sync, F: FnOnce() -> Arc<T>>( path: impl AsRef<str>, f: F, ) -> Option<Arc<T>>
Retrieves a value from the global cache or loads it from a closure if it does not exist.
Also returns None if the cached value is of the wrong type.
Sourcepub async fn get_or_else_async<T: Any + Send + Sync, F: AsyncFnOnce() -> Arc<T>>(
path: impl AsRef<str>,
f: F,
) -> Option<Arc<T>>
pub async fn get_or_else_async<T: Any + Send + Sync, F: AsyncFnOnce() -> Arc<T>>( path: impl AsRef<str>, f: F, ) -> Option<Arc<T>>
Retrieves a value from the global cache or loads it from an async closure if it does not
exist. Also returns None if the cached value is of the wrong type.
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 uncache(path: impl AsRef<str>)
pub fn uncache(path: impl AsRef<str>)
Removes a path from the global cache, if it exists.
Any values that have been acquired from the cache will remain valid until they are dropped.
Sourcepub fn clear()
pub fn clear()
Removes all paths from the global cache.
This is dangerous, as it can cause other crates to lose their dependent values. Any values that have been acquired from the cache will remain valid until they are dropped.
If you want a safer alternative, iterate and use uncache.
Sourcepub fn namespaced_paths(namespace: impl AsRef<str>) -> HashSet<String>
pub fn namespaced_paths(namespace: impl AsRef<str>) -> HashSet<String>
Returns all paths starting with namespace, stripping the namespace prefix.
This is only a snapshot, and future insertions and removals will not be reflected. Some entries may be in the process of being written, but most functions will wait until they are ready.
Sourcepub async fn namespaced_paths_async(
namespace: impl AsRef<str>,
) -> HashSet<String>
pub async fn namespaced_paths_async( namespace: impl AsRef<str>, ) -> HashSet<String>
Returns all paths starting with namespace asynchronously, stripping the namespace
prefix.
This is only a snapshot, and future insertions and removals will not be reflected. Some entries may be in the process of being written, but most functions will wait until they are ready.