diff options
| author | omagdy <omar.professional8777@gmail.com> | 2025-07-17 08:06:26 +0300 |
|---|---|---|
| committer | omagdy <omar.professional8777@gmail.com> | 2025-07-17 08:06:26 +0300 |
| commit | 38b649ea16d8ed053fd9222bfb9867e3432ee2a6 (patch) | |
| tree | a7fbde68ad869e1b74071207bdf7b7c159c7f75f /src/shared_cache.rs | |
| parent | c880c7ad3eba9546ce95bc268218c66a128d319f (diff) | |
| download | redis-rust-38b649ea16d8ed053fd9222bfb9867e3432ee2a6.tar.xz redis-rust-38b649ea16d8ed053fd9222bfb9867e3432ee2a6.zip | |
test: Moved tests to seprate files under tests folder for more structure
Diffstat (limited to 'src/shared_cache.rs')
| -rw-r--r-- | src/shared_cache.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/shared_cache.rs b/src/shared_cache.rs new file mode 100644 index 0000000..4d6aec2 --- /dev/null +++ b/src/shared_cache.rs @@ -0,0 +1,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>>>; |
