Expand description
Cache pre-compiled wasmer::Module
s.
The core of this module is the ModuleCache
trait, which is designed to
be implemented by different cache storage strategies, such as in-memory
caches (SharedCache
and ThreadLocalCache
), file-based caches
(FileSystemCache
), or distributed caches. Implementing custom caching
strategies allows you to optimize for your specific use case.
§Assumptions and Requirements
The module_cache
module makes several assumptions:
- Cache keys are unique, typically derived from the original
*.wasm
or*.wat
file, and using the same key to load or save will always result in the “same” module. - The
ModuleCache::load()
method will be called more often than theModuleCache::save()
method, allowing for cache implementations to optimize their strategy accordingly.
Cache implementations are encouraged to take
wasmer::Engine::deterministic_id()
into account when saving and loading
cached modules to ensure correct module retrieval.
Cache implementations should choose a suitable eviction policy and implement
invalidation transparently as part of ModuleCache::load()
or
ModuleCache::save()
.
§Combinators
The module_cache
module provides combinators for extending and combining
caching strategies. For example, you could use the FallbackCache
to
chain a fast in-memory cache with a slower file-based cache as a fallback.
Structs§
FallbackCache
is a combinator for theModuleCache
trait that enables the chaining of two caching strategies together, typically viaModuleCache::with_fallback()
.- File
System Cache sys-thread
A cache that saves modules to a folder on the host filesystem usingModule::serialize()
. - A
ModuleCache
based on aDashMap<ModuleHash, Module>
. - A cache that will cache modules in a thread-local variable.
Enums§
- Possible errors that may occur during
ModuleCache
operations.
Traits§
- A cache for compiled WebAssembly modules.
Functions§
- Get a
ModuleCache
which should be good enough for most in-memory use cases.