From 2939e5de820ec75bf43d5e270d09c41a179b72ce Mon Sep 17 00:00:00 2001 From: sarendsen Date: Mon, 14 Aug 2023 19:05:15 +0200 Subject: [PATCH] fix: Onnly refresh cache on expire --- Makefile | 2 +- src/routes.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 59a6390..57584b4 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ docker-run: run: - REPLEX_PORT=80 REPLEX_INCLUDE_WATCHED=0 REPLEX_REDIRECT_STREAMS=0 REPLEX_DISABLE_RELATED=1 REPLEX_DISABLE_LEAF_COUNT=0 REPLEX_DISABLE_USER_STATE=1 REPLEX_ENABLE_CONSOLE=0 REPLEX_CACHE_TTL=5 REPLEX_HOST=https://46-4-30-217.01b0839de64b49138531cab1bf32f7c2.plex.direct:42405 RUST_LOG="info,replex=debug" cargo watch -x run + REPLEX_PORT=80 REPLEX_INCLUDE_WATCHED=0 REPLEX_REDIRECT_STREAMS=0 REPLEX_DISABLE_RELATED=1 REPLEX_DISABLE_LEAF_COUNT=0 REPLEX_DISABLE_USER_STATE=1 REPLEX_ENABLE_CONSOLE=0 REPLEX_CACHE_TTL=500 REPLEX_HOST=https://46-4-30-217.01b0839de64b49138531cab1bf32f7c2.plex.direct:42405 RUST_LOG="info,replex=debug" cargo watch -x run # run: # REPLEX_ENABLE_CONSOLE=0 REPLEX_CACHE_TTL=0 REPLEX_HOST=https://46-4-30-217.01b0839de64b49138531cab1bf32f7c2.plex.direct:42405 RUST_LOG="info" cargo run diff --git a/src/routes.rs b/src/routes.rs index a9c0f62..4a73877 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -14,6 +14,7 @@ use crate::url::*; use crate::utils::*; use itertools::Itertools; use moka::future::Cache as MokaCache; +use moka::notification::RemovalCause; use moka::sync::Cache as MokaCacheSync; use moka::sync::CacheBuilder as MokaCacheBuilder; use salvo::cache::{Cache, CachedEntry}; @@ -396,7 +397,11 @@ pub fn auto_refresh_cache() -> Cache, RequestIssuer> { } // TODO: Maybe stop after a month? we can add a timestamp header to the key when first cached. - let listener = move |k: Arc, v: CachedEntry, cause| { + let listener = move |k: Arc, v: CachedEntry, cause: RemovalCause| { + if cause != RemovalCause::Expired { + return + } + let z = k.clone(); let values_list = cache_key_to_values(&z); let uri = values_list.get("uri").unwrap().to_string();