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 {
34 tool: tool.to_string(),
35 args_hash,
36 };
37 self.cache.get_owned(&key)
38 }
39
40 pub fn insert(&self, tool: &str, args_hash: u64, result: bool) {
42 let key = ValidationKey {
43 tool: tool.to_string(),
44 args_hash,
45 };
46 self.cache.insert(key, result, 1); }
48}
49
50impl Default for ValidationCache {
51 fn default() -> Self {
52 Self::new(Duration::from_secs(300)) }
54}