1 个稳定版本

1.0.1 2021 年 2 月 5 日

#714WebAssembly

MIT 许可证

215KB
3.5K SLoC

wasmer-cache 构建状态 加入 Wasmer Slack MIT 许可证

wasmer-cache crate 允许在您的系统中缓存 WebAssembly 模块(类型为 wasmer::Module),以便下次使用模块时不涉及编译时间。

用法

Cache 特性代表一个通用的缓存,用于存储和加载编译后的 WebAssembly 模块。类型 FileSystemCache 实现 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(())
}

依赖

~10MB
~209K SLoC