greppy/daemon/
cache.rs

1use crate::search::SearchResponse;
2use lru::LruCache;
3use std::num::NonZeroUsize;
4
5pub struct QueryCache {
6    cache: LruCache<String, SearchResponse>,
7}
8
9impl QueryCache {
10    pub fn new() -> Self {
11        Self {
12            cache: LruCache::new(NonZeroUsize::new(100).unwrap()),
13        }
14    }
15
16    pub fn get(&mut self, key: &str) -> Option<&SearchResponse> {
17        self.cache.get(key)
18    }
19
20    pub fn put(&mut self, key: String, value: SearchResponse) {
21        self.cache.put(key, value);
22    }
23
24    pub fn clear_project(&mut self, _project_path: &str) {
25        // Naive implementation: iterate and remove keys starting with project_path
26        // LruCache doesn't support retain efficiently, so we might need a better structure
27        // or just clear everything for now if it's too complex.
28        // For now, let's just clear everything to be safe and simple.
29        self.cache.clear();
30    }
31}