fix: fix caching routine about eviction
This commit is contained in:
parent
c20e80b64c
commit
460562183e
3 changed files with 13 additions and 12 deletions
|
|
@ -75,7 +75,7 @@ s2n-quic-rustls = { path = "../submodules/s2n-quic/quic/s2n-quic-rustls/", optio
|
|||
|
||||
# cache
|
||||
http-cache-semantics = { path = "../submodules/rusty-http-cache-semantics/" }
|
||||
moka = { version = "0.11.3", features = ["future"] }
|
||||
moka = { version = "0.11.3", features = ["future", "sync"] }
|
||||
|
||||
# cookie handling for sticky cookie
|
||||
chrono = { version = "0.4.26", default-features = false, features = [
|
||||
|
|
|
|||
|
|
@ -106,11 +106,12 @@ impl RpxyCache {
|
|||
};
|
||||
|
||||
let Ok(mut file) = File::open(&filepath.clone()).await else {
|
||||
warn!("Cache file doesn't exist. Remove pointer cache.");
|
||||
let my_cache = self.inner.clone();
|
||||
self.runtime_handle.spawn(async move {
|
||||
my_cache.invalidate(&moka_key).await;
|
||||
});
|
||||
warn!("Cache file object doesn't exist. Remove cache entry.");
|
||||
self.inner.invalidate(&moka_key).await;
|
||||
// let my_cache = self.inner.clone();
|
||||
// self.runtime_handle.spawn(async move {
|
||||
// my_cache.invalidate(&moka_key).await;
|
||||
// });
|
||||
return None;
|
||||
};
|
||||
let (body_sender, res_body) = Body::channel();
|
||||
|
|
@ -134,11 +135,12 @@ impl RpxyCache {
|
|||
} else {
|
||||
// Evict stale cache entry here
|
||||
debug!("Evict stale cache entry and file object: {moka_key}");
|
||||
let my_cache = self.inner.clone();
|
||||
self.runtime_handle.spawn(async move {
|
||||
// eviction listener will be activated during invalidation.
|
||||
my_cache.invalidate(&moka_key).await;
|
||||
});
|
||||
self.inner.invalidate(&moka_key).await;
|
||||
// let my_cache = self.inner.clone();
|
||||
// self.runtime_handle.spawn(async move {
|
||||
// eviction listener will be activated during invalidation.
|
||||
// my_cache.invalidate(&moka_key).await;
|
||||
// });
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ where
|
|||
async fn request(&self, req: Request<B>) -> Result<Response<Body>, Self::Error> {
|
||||
let mut synth_req = None;
|
||||
if self.cache.is_some() {
|
||||
debug!("Search cache first");
|
||||
if let Some(cached_response) = self.cache.as_ref().unwrap().get(&req).await {
|
||||
// if found, return it as response.
|
||||
debug!("Cache hit - Return from cache");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue