clache/lib.rs
1//! Lightweight, path-based caching utilities for various use cases.
2//!
3//! Clache provides two mechanisms for caching:
4//!
5//! - The [`GlobalCache`] requires less boilerplate and can operate on dynamic types. It is more
6//! suitable for an asset system, for example.
7//! - [`LocalCache`]s are less flexible, but more efficient. Unlike the [`GlobalCache`], they
8//! store static types and are more suitable when paths are not linked to the filesystem, as a
9//! single path can be distinctly cached for different instances and types.
10//!
11//! ## Choosing a cache
12//!
13//! Use a [`LocalCache`] when:
14//! - Are only caching one, known type.
15//! - Are making a subsystem or the cache belongs to an object.
16//! - And want more performance.
17//!
18//! Use the [`GlobalCache`] when:
19//! - You want easy shared access.
20//! - Are caching multiple/dynamic types.
21//! - Or paths are uniquely identifying.
22//!
23//! ## Multi-threading and async support
24//!
25//! Both types of caches are thread-safe and async-safe. Almost every function has a blocking and
26//! async variant, with the exception of [`uncache`] and [`clear`].
27//!
28//! [`RwLock`]: std::sync::RwLock
29//! [`Arc`]: std::sync::Arc
30//! [`LocalCache`]: crate::LocalCache
31//! [`GlobalCache`]: crate::GlobalCache
32//! [`get_or_else_async`]: crate::GlobalCache::get_or_else_async
33//! [`uncache`]: crate::GlobalCache::uncache
34//! [`clear`]: crate::GlobalCache::clear
35
36mod fused_rw;
37
38pub mod global_cache;
39pub use global_cache::GlobalCache;
40
41pub mod local_cache;
42pub use local_cache::LocalCache;
43
44#[doc(hidden)]
45pub mod prelude {
46 pub use crate::GlobalCache;
47 pub use crate::LocalCache;
48}