Skip to content

Commit

Permalink
fix: expire hero image cache if not found after a day
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Oct 30, 2023
1 parent 37e2f13 commit 3c2777d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 0 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ rstest = "0.18.1"
#[features]
#test = []

# [patch.crates-io]
# salvo-proxy = { path = "../salvo/crates/proxy" }
# salvo_core = { path = "../salvo/crates/core" }
[patch.crates-io]
salvo-proxy = { path = "../salvo/crates/proxy" }
salvo_core = { path = "../salvo/crates/core" }
#salvo-cache = { path = "../salvo/crates/cache" }

[profile.release]
Expand Down
5 changes: 4 additions & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ pub enum Expiration {
Never,
/// Global TTL from the config
Global,
/// Expires after a mint
/// Expires after a month
Month,
/// Expires after a day
Day,
}

impl Expiration {
Expand All @@ -66,6 +68,7 @@ impl Expiration {
Expiration::Never => None,
Expiration::Global => Some(Duration::from_secs(config.cache_ttl)),
Expiration::Month => Some(Duration::from_secs(30 * 24 * 60 * 60)),
Expiration::Day => Some(Duration::from_secs(60 * 60 * 24)),
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,12 @@ impl MetaData {
}
}

let mut cache_expiry = crate::cache::Expiration::Month;
if image.is_none() {
cache_expiry = crate::cache::Expiration::Day;
}
let _ = GLOBAL_CACHE
.insert(cache_key, image.clone(), crate::cache::Expiration::Month)
.insert(cache_key, image.clone(), cache_expiry)
.await;
image
}
Expand Down
1 change: 0 additions & 1 deletion src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ where
res: &mut salvo::Response,
ctrl: &mut FlowCtrl,
) {
// let mut reqq = RequestBuilder::new(req.uri_mut().to_string(), req.method_mut().clone()).build();
self.inner.handle(req, depot, res, ctrl).await;
}
}
Expand Down

0 comments on commit 3c2777d

Please sign in to comment.