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
|
# cache
|
||||||
http-cache-semantics = { path = "../submodules/rusty-http-cache-semantics/" }
|
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
|
# cookie handling for sticky cookie
|
||||||
chrono = { version = "0.4.26", default-features = false, features = [
|
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 {
|
let Ok(mut file) = File::open(&filepath.clone()).await else {
|
||||||
warn!("Cache file doesn't exist. Remove pointer cache.");
|
warn!("Cache file object doesn't exist. Remove cache entry.");
|
||||||
let my_cache = self.inner.clone();
|
self.inner.invalidate(&moka_key).await;
|
||||||
self.runtime_handle.spawn(async move {
|
// let my_cache = self.inner.clone();
|
||||||
my_cache.invalidate(&moka_key).await;
|
// self.runtime_handle.spawn(async move {
|
||||||
});
|
// my_cache.invalidate(&moka_key).await;
|
||||||
|
// });
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let (body_sender, res_body) = Body::channel();
|
let (body_sender, res_body) = Body::channel();
|
||||||
|
|
@ -134,11 +135,12 @@ impl RpxyCache {
|
||||||
} else {
|
} else {
|
||||||
// Evict stale cache entry here
|
// Evict stale cache entry here
|
||||||
debug!("Evict stale cache entry and file object: {moka_key}");
|
debug!("Evict stale cache entry and file object: {moka_key}");
|
||||||
let my_cache = self.inner.clone();
|
self.inner.invalidate(&moka_key).await;
|
||||||
self.runtime_handle.spawn(async move {
|
// let my_cache = self.inner.clone();
|
||||||
// eviction listener will be activated during invalidation.
|
// self.runtime_handle.spawn(async move {
|
||||||
my_cache.invalidate(&moka_key).await;
|
// eviction listener will be activated during invalidation.
|
||||||
});
|
// my_cache.invalidate(&moka_key).await;
|
||||||
|
// });
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ where
|
||||||
async fn request(&self, req: Request<B>) -> Result<Response<Body>, Self::Error> {
|
async fn request(&self, req: Request<B>) -> Result<Response<Body>, Self::Error> {
|
||||||
let mut synth_req = None;
|
let mut synth_req = None;
|
||||||
if self.cache.is_some() {
|
if self.cache.is_some() {
|
||||||
debug!("Search cache first");
|
|
||||||
if let Some(cached_response) = self.cache.as_ref().unwrap().get(&req).await {
|
if let Some(cached_response) = self.cache.as_ref().unwrap().get(&req).await {
|
||||||
// if found, return it as response.
|
// if found, return it as response.
|
||||||
debug!("Cache hit - Return from cache");
|
debug!("Cache hit - Return from cache");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue