Fix problem with caching partial responses.

This commit is contained in:
Ara Sadoyan
2026-11-02 17:03:53 +01:00
parent d6936a2a0e
commit de7cc16213
2 changed files with 12 additions and 8 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ pub async fn init_cache(config: Arc<AppConfig>) {
let manager = Manager::new(cache_size); let manager = Manager::new(cache_size);
let _ = EVICTION.set(manager); let _ = EVICTION.set(manager);
GLOBAL_STORAGE.set(Box::new(MemCache::new())).ok(); 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 { "redis" => match RedisCache::new(&storage, ttl).await {
Ok(cache) => { Ok(cache) => {
+11 -7
View File
@@ -78,13 +78,17 @@ impl ProxyHttp for LB {
}); });
Ok(CacheKey::new(primary_key, host /* host is just for debugging */)) Ok(CacheKey::new(primary_key, host /* host is just for debugging */))
} }
fn request_cache_filter(&self, session: &mut Session, _ctx: &mut Self::CTX) -> Result<()> { 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 {
if self.cache_enabled && session.req_header().method == Method::GET && !has_auth { return Ok(());
if let Some(storage) = GLOBAL_STORAGE.get() { }
let eviction_mgr = EVICTION.get().map(|e| e as &(dyn pingora_cache::eviction::EvictionManager + Sync)); let has_auth = ctx.upstream_peer.as_ref().is_some_and(|m| m.authorization.is_some()) || ctx.extraparams.authentication.is_some();
session.cache.enable(storage.as_ref(), eviction_mgr, None, Some(&*CACHE_LOCK), None); 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(()) Ok(())
} }