Don't hash for the cache if it's disabled (#2816)
This fixes an issue where even if the wasmtime cache was disabled we're still calculating the sha256 of modules for the hash key. This hash was then simply discarded if the cache was disabled!
This commit is contained in:
10
crates/cache/src/lib.rs
vendored
10
crates/cache/src/lib.rs
vendored
@@ -48,17 +48,17 @@ impl<'config> ModuleCacheEntry<'config> {
|
|||||||
T: Hash,
|
T: Hash,
|
||||||
U: Serialize + for<'a> Deserialize<'a>,
|
U: Serialize + for<'a> Deserialize<'a>,
|
||||||
{
|
{
|
||||||
|
let inner = match &self.0 {
|
||||||
|
Some(inner) => inner,
|
||||||
|
None => return compute(state),
|
||||||
|
};
|
||||||
|
|
||||||
let mut hasher = Sha256Hasher(Sha256::new());
|
let mut hasher = Sha256Hasher(Sha256::new());
|
||||||
state.hash(&mut hasher);
|
state.hash(&mut hasher);
|
||||||
let hash: [u8; 32] = hasher.0.finalize().into();
|
let hash: [u8; 32] = hasher.0.finalize().into();
|
||||||
// standard encoding uses '/' which can't be used for filename
|
// standard encoding uses '/' which can't be used for filename
|
||||||
let hash = base64::encode_config(&hash, base64::URL_SAFE_NO_PAD);
|
let hash = base64::encode_config(&hash, base64::URL_SAFE_NO_PAD);
|
||||||
|
|
||||||
let inner = match &self.0 {
|
|
||||||
Some(inner) => inner,
|
|
||||||
None => return compute(state),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(cached_val) = inner.get_data(&hash) {
|
if let Some(cached_val) = inner.get_data(&hash) {
|
||||||
let mod_cache_path = inner.root_path.join(&hash);
|
let mod_cache_path = inner.root_path.join(&hash);
|
||||||
inner.cache_config.on_cache_get_async(&mod_cache_path); // call on success
|
inner.cache_config.on_cache_get_async(&mod_cache_path); // call on success
|
||||||
|
|||||||
Reference in New Issue
Block a user