agcodex_core/context_engine/
cache.rs

1//! Simple cache scaffolding for context engine.
2use std::collections::HashMap;
3use std::hash::Hash;
4
5pub trait Cache<K, V> {
6    fn get(&self, key: &K) -> Option<V>;
7    fn insert(&mut self, key: K, value: V);
8    fn clear(&mut self);
9}
10
11#[derive(Debug, Default)]
12pub struct InMemoryCache<K, V> {
13    map: HashMap<K, V>,
14}
15
16impl<K: Eq + Hash + Clone, V: Clone> Cache<K, V> for InMemoryCache<K, V> {
17    fn get(&self, key: &K) -> Option<V> {
18        self.map.get(key).cloned()
19    }
20    fn insert(&mut self, key: K, value: V) {
21        self.map.insert(key, value);
22    }
23    fn clear(&mut self) {
24        self.map.clear();
25    }
26}