vtcode_core/tools/
validation_cache.rs1use std::time::Duration;
2
3use crate::cache::{CacheKey, EvictionPolicy, UnifiedCache};
4
5#[derive(Debug, Clone, Hash, PartialEq, Eq)]
7struct ValidationKey {
8 tool: String,
9 args_hash: u64,
10}
11
12impl CacheKey for ValidationKey {
13 fn to_cache_key(&self) -> String {
14 format!("{}:{}", self.tool, self.args_hash)
15 }
16}
17
18pub struct ValidationCache {
20 cache: UnifiedCache<ValidationKey, bool>,
21}
22
23impl ValidationCache {
24 pub fn new(ttl: Duration) -> Self {
26 Self {
27 cache: UnifiedCache::new(1000, ttl, EvictionPolicy::TtlOnly),
28 }
29 }
30
31 pub fn check(&self, tool: &str, args_hash: u64) -> Option<bool> {
33 let key = ValidationKey { tool: tool.to_string(), args_hash };
34 self.cache.get_owned(&key)
35 }
36
37 pub fn insert(&self, tool: &str, args_hash: u64, result: bool) {
39 let key = ValidationKey { tool: tool.to_string(), args_hash };
40 self.cache.insert(key, result, 1); }
42}
43
44impl Default for ValidationCache {
45 fn default() -> Self {
46 Self::new(Duration::from_secs(300)) }
48}