use std::path::Path;
pub trait CacheLayer: Send + Sync {
fn name(&self) -> &str;
fn is_populated(&self) -> bool;
fn invalidate_files(&mut self, changed_files: &[&Path]);
fn invalidate_all(&mut self);
}
pub struct CacheCoordinator {
layers: Vec<Box<dyn CacheLayer>>,
}
impl CacheCoordinator {
pub fn new() -> Self {
Self { layers: Vec::new() }
}
pub fn register(&mut self, layer: Box<dyn CacheLayer>) {
tracing::debug!("Registered cache layer: {}", layer.name());
self.layers.push(layer);
}
pub fn invalidate_files(&mut self, changed_files: &[&Path]) {
for layer in &mut self.layers {
layer.invalidate_files(changed_files);
tracing::debug!(
"Invalidated {} files in cache layer: {}",
changed_files.len(),
layer.name()
);
}
}
pub fn invalidate_all(&mut self) {
for layer in &mut self.layers {
layer.invalidate_all();
tracing::debug!("Invalidated all data in cache layer: {}", layer.name());
}
}
pub fn all_populated(&self) -> bool {
self.layers.iter().all(|l| l.is_populated())
}
}
impl Default for CacheCoordinator {
fn default() -> Self {
Self::new()
}
}