A caching library for Bevy that provides a manifest-based cache for storing and retrieving assets with expiration and persistence support.
Note
I designed this for my personal use, however, I am publishing it here in case it is useful to others and welcome feedback, issues, and contributions.
- Manifest-based cache that tracks cached assets and their metadata
- Store and retrieve assets by key
- Automatic expiration of cached entries based on global or per-entry max age
- Persistence of the cache manifest to disk so the cache survives application restarts
- Removal of expired or individual cache entries
- Support for generating
cache://asset paths for use in Bevy asset loading
Add the BevyCachePlugin to your Bevy app, passing in a unique application name that will be used to determine the cache directory.
Use this for caching assets that you want to persist across runs of your Bevy app, optionally with expiration, and to be able to load them via cache:// paths in the Bevy asset system.
Systems can use the Cache system param to work with both CacheManifest and CacheConfig through a single parameter:
use bevy::prelude::*;
use bevy_cache::prelude::*;
fn cache_image(mut cache: Cache, asset_server: Res<AssetServer>) {
if !cache.is_cached("portraits/player") {
cache
.store(
"portraits/player",
"png",
std::io::Cursor::new(vec![1, 2, 3]),
None,
)
.expect("cache write failed");
}
let _image: Handle<Image> = cache
.load_cached(&asset_server, "portraits/player")
.expect("cache load failed");
}See examples.
| bevy | bevy-cache |
|---|---|
| 0.18 | 0.1 - 0.2 |
Contributions are welcome! Please open issues or submit pull requests to contribute improvements, bug fixes, or new features.
This project is licensed under the MIT License. See the LICENSE file for details.
