Skip to main content

vtcode_core/tools/registry/
cache.rs

1use serde_json::json;
2
3use crate::tools::cache::{FILE_CACHE, FileCache};
4
5use super::ToolRegistry;
6
7impl ToolRegistry {
8    /// Access the file cache used by this registry.
9    ///
10    /// Returns the global `FileCache` instance. In a future phase, this will
11    /// return a per-registry cache instance to enable test isolation.
12    pub fn file_cache(&self) -> &'static FileCache {
13        &FILE_CACHE
14    }
15
16    pub async fn cache_stats(&self) -> serde_json::Value {
17        let stats = self.file_cache().stats().await;
18        json!({
19            "hits": stats.hits,
20            "misses": stats.misses,
21            "entries": stats.entries,
22            "file_entries": stats.file_entries,
23            "directory_entries": stats.directory_entries,
24            "total_size_bytes": stats.total_size_bytes,
25            "file_size_bytes": stats.file_size_bytes,
26            "directory_size_bytes": stats.directory_size_bytes,
27            "hit_rate": if stats.hits + stats.misses > 0 {
28                stats.hits as f64 / (stats.hits + stats.misses) as f64
29            } else { 0.0 }
30        })
31    }
32
33    pub async fn clear_cache(&self) {
34        self.file_cache().clear().await;
35    }
36}