Lightweight, path-based caching utilities for various use cases.
Clache provides two mechanisms for caching:
- The
GlobalCacherequires less boilerplate and can operate on dynamic types. It is more suitable for an asset system, for example. LocalCaches are less flexible, but more efficient. Unlike theGlobalCache, 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.
Async support
Both types of caches support asynchronous loading. Through the get_or_else_async and
get_or_try_async functions.
Thread safety
Both types of caches use RwLock internally and share cached values via Arc, making
them both thread-safe and efficient.