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