From 38b649ea16d8ed053fd9222bfb9867e3432ee2a6 Mon Sep 17 00:00:00 2001 From: omagdy Date: Thu, 17 Jul 2025 08:06:26 +0300 Subject: test: Moved tests to seprate files under tests folder for more structure --- src/shared_cache.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/shared_cache.rs (limited to 'src/shared_cache.rs') 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, // 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>>; -- cgit v1.2.3