From 11ba5195a8c478f5f0f42bc65f54fa31c6aadc66 Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Tue, 11 Mar 2025 22:54:47 -0400 Subject: [PATCH] fix: remove redundant calculation of storage key. --- src/cache.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index 82416a2..b87ab32 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -309,8 +309,8 @@ where let method = request.method(); let uri = request.uri(); + let key = storage_key(method, uri); if matches!(*method, Method::GET | Method::HEAD) { - let key = storage_key(method, uri); match self.storage.get(&key).await { Ok(Some((response, policy))) => { debug!( @@ -351,7 +351,8 @@ where } } - self.send_upstream(request, CacheLookupStatus::Miss).await + self.send_upstream(key, request, CacheLookupStatus::Miss) + .await } /// Sends the original request upstream. @@ -359,6 +360,7 @@ where /// Caches the response if the response is cacheable. async fn send_upstream( &self, + key: String, request: impl Request, lookup_status: CacheLookupStatus, ) -> Result>> { @@ -370,7 +372,6 @@ where response.set_cache_status(lookup_status, CacheStatus::Miss); - let key = storage_key(&request_like.method, &request_like.uri); if matches!(request_like.method, Method::GET | Method::HEAD) && response.status() == StatusCode::OK && policy.is_storable()