mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 05:38:19 +00:00
30 lines
1.3 KiB
Markdown
30 lines
1.3 KiB
Markdown
# `wasmer-cache` [](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [](https://slack.wasmer.io) [](https://github.com/wasmerio/wasmer/blob/master/LICENSE)
|
|
|
|
The `wasmer-cache` crate allows to cache WebAssembly modules (of kind
|
|
`wasmer::Module`) in your system, so that next uses of the module does
|
|
imply a compilation time.
|
|
|
|
## Usage
|
|
|
|
The `Cache` trait represents a generic cache for storing and loading
|
|
compiled WebAssembly modules. The `FileSystemCache` type implements
|
|
`Cache` to store cache on the file system.
|
|
|
|
```rust
|
|
use wasmer::{DeserializeError, Module, SerializeError};
|
|
use wasmer_cache::{Cache, FileSystemCache, Hash};
|
|
|
|
fn store_module(module: &Module, bytes: &[u8]) -> Result<(), SerializeError> {
|
|
// Create a new file system cache.
|
|
let mut fs_cache = FileSystemCache::new("some/directory/goes/here")?;
|
|
|
|
// Compute a key for a given WebAssembly binary
|
|
let hash = Hash::generate(bytes);
|
|
|
|
// Store a module into the cache given a key
|
|
fs_cache.store(hash, module.clone())?;
|
|
|
|
Ok(())
|
|
}
|
|
```
|