Module module_cache

Source
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 *.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 the ModuleCache::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§

FallbackCache
FallbackCache is a combinator for the ModuleCache trait that enables the chaining of two caching strategies together, typically via ModuleCache::with_fallback().
FileSystemCache
A cache that saves modules to a folder on the host filesystem using Module::serialize().
HashedModuleData
A wrapper around Webassembly code and its hash.
SharedCache
A ModuleCache based on a [DashMap]<[ModuleHash], Module>.
ThreadLocalCache
A cache that will cache modules in a thread-local variable.

Enums§

CacheError
Possible errors that may occur during ModuleCache operations.

Traits§

ModuleCache
A cache for compiled WebAssembly modules.

Functions§

in_memory
Get a ModuleCache which should be good enough for most in-memory use cases.