Expand description
Cache pre-compiled wasmer::Modules.
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
*.wasmor*.watfile, 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.
Modules§
- fallback 🔒
- filesystem 🔒
- hashed_
module 🔒 - shared 🔒
- thread_
local 🔒 - types 🔒
Structs§
- Fallback
Cache FallbackCacheis a combinator for theModuleCachetrait that enables the chaining of two caching strategies together, typically viaModuleCache::with_fallback().- File
System Cache - A cache that saves modules to a folder on the host filesystem using
Module::serialize(). - Hashed
Module Data - A wrapper around Webassembly code and its hash.
- Shared
Cache - A
ModuleCachebased on a[DashMap]<[ModuleHash], Module>. - Thread
Local Cache - A cache that will cache modules in a thread-local variable.
Enums§
- Cache
Error - Possible errors that may occur during
ModuleCacheoperations.
Traits§
- Module
Cache - A cache for compiled WebAssembly modules.
Functions§
- in_
memory - Get a
ModuleCachewhich should be good enough for most in-memory use cases.