Skip to content

captkirk88/bevy-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bevy-dlc


Bevy Cache

Crates.io docs.rs License: MIT

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.

Features

  • 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

Usage

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");
}

Examples

See examples.

Compatibility

bevy bevy-cache
0.18 0.1 - 0.2

Contributing

Contributions are welcome! Please open issues or submit pull requests to contribute improvements, bug fixes, or new features.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Caching of runtime generated assets for Bevy

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages