The wasmer-cache crate provides mechanisms to cache compiled WebAssembly modules (wasmer::Module). By caching these modules, you can avoid the overhead of re-compilation on subsequent uses of the same module.
Core Abstractions
Cache trait: A generic interface for storing and loading compiled WebAssembly modules.FileSystemCache: A concrete implementation of the Cache trait that persists modules to the local file system.Hash: Used to generate unique keys for WebAssembly binaries to identify them within the cache.
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
}