use std::time::{Duration, Instant};
#[derive(Debug, Clone)]
pub struct CacheEntry {
value: Option<String>,
cached_at: Instant,
access_count: u64,
}
impl CacheEntry {
pub fn new(value: Option<String>) -> Self {
Self {
value,
cached_at: Instant::now(),
access_count: 0,
}
}
pub fn is_expired(&self, ttl: Duration) -> bool {
self.cached_at.elapsed() > ttl
}
pub fn access(&mut self) -> &Option<String> {
self.access_count += 1;
&self.value
}
pub fn cached_at(&self) -> Instant {
self.cached_at
}
pub fn access_count(&self) -> u64 {
self.access_count
}
pub fn value(&self) -> &Option<String> {
&self.value
}
}