pub mod cache_config;
pub mod cache_manager;
pub mod invalidation;
pub mod plan_cache;
pub mod result_cache;
pub mod subquery_cache;
pub use cache_config::{CacheConfig, EvictionPolicy};
pub use cache_manager::CacheManager;
pub use invalidation::{InvalidationEvent, InvalidationManager};
pub use plan_cache::{PlanCache, PlanCacheEntry, PlanCacheKey};
pub use result_cache::ResultCache;
pub use subquery_cache::{
SubqueryCache, SubqueryCacheHit, SubqueryCacheKey, SubqueryResult, SubqueryType,
};
use std::time::{Duration, Instant};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CacheLevel {
L1,
L2,
L3,
}
#[derive(Debug, Clone)]
pub struct CacheEntryMetadata {
pub created_at: Instant,
pub last_accessed: Instant,
pub access_count: u32,
pub size_bytes: usize,
pub ttl: Option<Duration>,
pub level: CacheLevel,
pub tags: Vec<String>, }
impl CacheEntryMetadata {
pub fn new(size_bytes: usize, level: CacheLevel) -> Self {
let now = Instant::now();
Self {
created_at: now,
last_accessed: now,
access_count: 0,
size_bytes,
ttl: None,
level,
tags: Vec::new(),
}
}
pub fn with_ttl(mut self, ttl: Duration) -> Self {
self.ttl = Some(ttl);
self
}
pub fn with_tags(mut self, tags: Vec<String>) -> Self {
self.tags = tags;
self
}
pub fn is_expired(&self) -> bool {
if let Some(ttl) = self.ttl {
self.created_at.elapsed() > ttl
} else {
false
}
}
pub fn update_access(&mut self) {
self.last_accessed = Instant::now();
self.access_count += 1;
}
}
pub trait CacheKey:
std::fmt::Debug + Clone + PartialEq + Eq + std::hash::Hash + Send + Sync
{
#[allow(dead_code)] fn cache_key(&self) -> String;
fn tags(&self) -> Vec<String> {
Vec::new()
}
}
pub trait CacheValue: std::fmt::Debug + Clone + Send + Sync {
fn size_bytes(&self) -> usize;
fn is_valid(&self) -> bool {
true
}
}