mirror of
https://github.com/sadoyan/aralez.git
synced 2026-11-24 21:59:07 +08:00
Fix problem with caching partial responses.
This commit is contained in:
Vendored
+1
-1
@@ -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) => {
|
||||||
|
|||||||
@@ -78,14 +78,18 @@ 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(());
|
||||||
|
}
|
||||||
|
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() {
|
if let Some(storage) = GLOBAL_STORAGE.get() {
|
||||||
let eviction_mgr = EVICTION.get().map(|e| e as &(dyn pingora_cache::eviction::EvictionManager + Sync));
|
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);
|
session.cache.enable(storage.as_ref(), eviction_mgr, None, Some(&*CACHE_LOCK), None);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn response_cache_filter(&self, _session: &Session, resp: &ResponseHeader, _ctx: &mut Self::CTX) -> Result<RespCacheable> {
|
fn response_cache_filter(&self, _session: &Session, resp: &ResponseHeader, _ctx: &mut Self::CTX) -> Result<RespCacheable> {
|
||||||
|
|||||||
Reference in New Issue
Block a user