From 5c4c03d2787833a7d1422f13a30b85ad3d75821a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 8 Apr 2021 11:48:24 -0500 Subject: [PATCH] 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! --- crates/cache/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/cache/src/lib.rs b/crates/cache/src/lib.rs index 9fe69c5baf..f29dd21056 100644 --- a/crates/cache/src/lib.rs +++ b/crates/cache/src/lib.rs @@ -48,17 +48,17 @@ impl<'config> ModuleCacheEntry<'config> { T: Hash, U: Serialize + for<'a> Deserialize<'a>, { + let inner = match &self.0 { + Some(inner) => inner, + None => return compute(state), + }; + let mut hasher = Sha256Hasher(Sha256::new()); state.hash(&mut hasher); let hash: [u8; 32] = hasher.0.finalize().into(); // standard encoding uses '/' which can't be used for filename 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) { let mod_cache_path = inner.root_path.join(&hash); inner.cache_config.on_cache_get_async(&mod_cache_path); // call on success