Skip to content

Commit

Permalink
fix: Onnly refresh cache on expire
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Aug 14, 2023
1 parent 8f1ceb2 commit 2939e5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -396,7 +397,11 @@ pub fn auto_refresh_cache() -> Cache<MemoryStore<String>, RequestIssuer> {
}

// TODO: Maybe stop after a month? we can add a timestamp header to the key when first cached.
let listener = move |k: Arc<String>, v: CachedEntry, cause| {
let listener = move |k: Arc<String>, 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();
Expand Down

0 comments on commit 2939e5d

Please sign in to comment.