use std::collections::HashMap; use std::sync::Mutex; pub struct ThreadSafeCache { file_cache: Mutex>, // node_id -> (file_path, file_size) path_cache: Mutex>, // path -> node_id } impl ThreadSafeCache { pub fn new() -> Self { Self { file_cache: Mutex::new(HashMap::new()), path_cache: Mutex::new(HashMap::new()), } } pub fn insert_file(&self, node_id: &str, file_path: &str, file_size: u64) { let mut cache = self.file_cache.lock().unwrap(); cache.insert(node_id.to_string(), (file_path.to_string(), file_size)); } pub fn lookup_file(&self, node_id: &str) -> Option<(String, u64)> { let cache = self.file_cache.lock().unwrap(); cache.get(node_id).cloned() } pub fn insert_path(&self, path: &str, node_id: &str) { let mut cache = self.path_cache.lock().unwrap(); cache.insert(path.to_string(), node_id.to_string()); } pub fn lookup_path(&self, path: &str) -> Option { let cache = self.path_cache.lock().unwrap(); cache.get(path).cloned() } }