blob: 4d6aec2badbe9d810cdeaa7791d377f15044b46a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
use std::{
collections::HashMap,
sync::{Arc, Mutex},
time::{SystemTime, UNIX_EPOCH},
};
#[derive(Debug, Clone)]
pub struct CacheEntry {
pub value: String,
pub expires_at: Option<u64>, // Unix timestamp in milliseconds
}
impl CacheEntry {
pub fn is_expired(&self) -> bool {
if let Some(expiry) = self.expires_at {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64;
now > expiry
} else {
false
}
}
}
pub type SharedCache = Arc<Mutex<HashMap<String, CacheEntry>>>;
|