fix: correctly check cache expiry (#1114)

This commit is contained in:
Bjerg 2022-04-06 08:42:40 +02:00 committed by GitHub
parent c436d19a9c
commit 8f9832d1a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -101,7 +101,12 @@ impl Cache {
let reader = std::io::BufReader::new(std::fs::File::open(path).ok()?); let reader = std::io::BufReader::new(std::fs::File::open(path).ok()?);
if let Ok(inner) = serde_json::from_reader::<_, CacheEnvelope<T>>(reader) { if let Ok(inner) = serde_json::from_reader::<_, CacheEnvelope<T>>(reader) {
// If this does not return None then we have passed the expiry // If this does not return None then we have passed the expiry
if SystemTime::now().checked_sub(Duration::from_secs(inner.expiry)).is_some() { if SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time is before unix epoch")
.checked_sub(Duration::from_secs(inner.expiry))
.is_some()
{
return None return None
} }