aboutsummaryrefslogtreecommitdiffhomepage
path: root/pingora-cache/src/lib.rs
diff options
context:
space:
mode:
authorEdward Wang <[email protected]>2024-11-15 16:21:57 -0800
committerYuchen Wu <[email protected]>2024-12-13 16:25:31 -0800
commitdcb40b620eb49dd9482d108dbf6751048a3859ad (patch)
treebafa9908adf5a3aa250e605568542daafb1b30c2 /pingora-cache/src/lib.rs
parente955df8a9df8c3050c3d481fc3210c8dce019746 (diff)
downloadpingora-dcb40b620eb49dd9482d108dbf6751048a3859ad.tar.gz
pingora-dcb40b620eb49dd9482d108dbf6751048a3859ad.zip
Make cache eviction async
This prevents eviction from affecting the time to finish the request. Also adds a Display impl for CompactCacheKey.
Diffstat (limited to 'pingora-cache/src/lib.rs')
-rw-r--r--pingora-cache/src/lib.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/pingora-cache/src/lib.rs b/pingora-cache/src/lib.rs
index c65f602..f747672 100644
--- a/pingora-cache/src/lib.rs
+++ b/pingora-cache/src/lib.rs
@@ -19,6 +19,7 @@
use http::{method::Method, request::Parts as ReqHeader, response::Parts as RespHeader};
use key::{CacheHashKey, HashBinary};
use lock::WritePermit;
+use log::warn;
use pingora_error::Result;
use pingora_http::ResponseHeader;
use rustracing::tag::Tag;
@@ -751,16 +752,18 @@ impl HttpCache {
let cache_key = key.to_compact();
let meta = inner.meta.as_ref().unwrap();
let evicted = eviction.admit(cache_key, size, meta.0.internal.fresh_until);
- // TODO: make this async
+ // actual eviction can be done async
let span = inner.traces.child("eviction");
let handle = span.handle();
- for item in evicted {
- // TODO: warn/log the error
- let _ = inner
- .storage
- .purge(&item, PurgeType::Eviction, &handle)
- .await;
- }
+ let storage = inner.storage;
+ tokio::task::spawn(async move {
+ for item in evicted {
+ if let Err(e) = storage.purge(&item, PurgeType::Eviction, &handle).await
+ {
+ warn!("Failed to purge {item} during eviction for finish miss handler: {e}");
+ }
+ }
+ });
}
inner.traces.finish_miss_span();
Ok(())