From de7cc16213aa56f09374122660584a43330f9188 Mon Sep 17 00:00:00 2001 From: Ara Sadoyan Date: Mon, 2 Nov 2026 17:03:53 +0100 Subject: [PATCH] Fix problem with caching partial responses. --- src/cache/types.rs | 2 +- src/core/proxyhttp.rs | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cache/types.rs b/src/cache/types.rs index 2f00703..2dc4f1e 100644 --- a/src/cache/types.rs +++ b/src/cache/types.rs @@ -27,7 +27,7 @@ pub async fn init_cache(config: Arc) { let manager = Manager::new(cache_size); let _ = EVICTION.set(manager); GLOBAL_STORAGE.set(Box::new(MemCache::new())).ok(); - info!("Cache initialized successfully. Storage: {}", storage); + info!("Cache initialized successfully. Storage: {}, Size: {}mb", storage, size); } "redis" => match RedisCache::new(&storage, ttl).await { Ok(cache) => { diff --git a/src/core/proxyhttp.rs b/src/core/proxyhttp.rs index 0bba09d..292c6a1 100644 --- a/src/core/proxyhttp.rs +++ b/src/core/proxyhttp.rs @@ -78,13 +78,17 @@ impl ProxyHttp for LB { }); Ok(CacheKey::new(primary_key, host /* host is just for debugging */)) } - fn request_cache_filter(&self, session: &mut Session, _ctx: &mut Self::CTX) -> Result<()> { - let has_auth = _ctx.upstream_peer.as_ref().map(|m| m.authorization.is_some()).unwrap_or(false) || _ctx.extraparams.authentication.is_some(); - if self.cache_enabled && session.req_header().method == Method::GET && !has_auth { - if let Some(storage) = GLOBAL_STORAGE.get() { - let eviction_mgr = EVICTION.get().map(|e| e as &(dyn pingora_cache::eviction::EvictionManager + Sync)); - session.cache.enable(storage.as_ref(), eviction_mgr, None, Some(&*CACHE_LOCK), None); - } + fn request_cache_filter(&self, session: &mut Session, ctx: &mut Self::CTX) -> Result<()> { + if !self.cache_enabled || session.req_header().method != Method::GET { + return Ok(()); + } + let has_auth = ctx.upstream_peer.as_ref().is_some_and(|m| m.authorization.is_some()) || ctx.extraparams.authentication.is_some(); + if has_auth || session.get_header("range").is_some() { + return Ok(()); + } + if let Some(storage) = GLOBAL_STORAGE.get() { + let eviction_mgr = EVICTION.get().map(|e| e as &(dyn pingora_cache::eviction::EvictionManager + Sync)); + session.cache.enable(storage.as_ref(), eviction_mgr, None, Some(&*CACHE_LOCK), None); } Ok(()) }