Struct wasmtime_cache::ModuleCacheEntry
source · pub struct ModuleCacheEntry<'config>(_);
Expand description
Module level cache entry.
Implementations§
source§impl<'config> ModuleCacheEntry<'config>
impl<'config> ModuleCacheEntry<'config>
sourcepub fn new<'data>(
compiler_name: &str,
cache_config: &'config CacheConfig
) -> Self
pub fn new<'data>(
compiler_name: &str,
cache_config: &'config CacheConfig
) -> Self
Create the cache entry.
sourcepub fn get_data<T, U, E>(
&self,
state: T,
compute: fn(_: &T) -> Result<U, E>
) -> Result<U, E>where
T: Hash,
U: Serialize + for<'a> Deserialize<'a>,
pub fn get_data<T, U, E>(
&self,
state: T,
compute: fn(_: &T) -> Result<U, E>
) -> Result<U, E>where
T: Hash,
U: Serialize + for<'a> Deserialize<'a>,
Gets cached data if state matches, otherwise calls compute
.
Data is automatically serialized/deserialized with bincode
.
sourcepub fn get_data_raw<T, U, E>(
&self,
state: &T,
compute: fn(_: &T) -> Result<U, E>,
serialize: fn(_: &T, _: &U) -> Option<Vec<u8>>,
deserialize: fn(_: &T, _: Vec<u8>) -> Option<U>
) -> Result<U, E>where
T: Hash,
pub fn get_data_raw<T, U, E>(
&self,
state: &T,
compute: fn(_: &T) -> Result<U, E>,
serialize: fn(_: &T, _: &U) -> Option<Vec<u8>>,
deserialize: fn(_: &T, _: Vec<u8>) -> Option<U>
) -> Result<U, E>where
T: Hash,
Gets cached data if state matches, otherwise calls compute
.
If the cache is disabled or no cached data is found then compute
is
called to calculate the data. If the data was found in cache it is
passed to deserialize
, which if successful will be the returned value.
When computed the serialize
function is used to generate the bytes
from the returned value.