Skip to main content

xbp_analysis/adapters/
cache.rs

1//! In-memory analysis cache.
2
3use crate::domain::types::Finding;
4use crate::ports::outbound::AnalysisCache;
5use std::collections::HashMap;
6use std::sync::Mutex;
7
8#[derive(Default)]
9pub struct MemoryCache {
10    inner: Mutex<HashMap<String, Vec<Finding>>>,
11}
12
13impl AnalysisCache for MemoryCache {
14    fn get(&self, key: &str) -> Option<Vec<Finding>> {
15        self.inner.lock().ok()?.get(key).cloned()
16    }
17
18    fn put(&self, key: &str, findings: &[Finding]) {
19        if let Ok(mut g) = self.inner.lock() {
20            g.insert(key.to_string(), findings.to_vec());
21        }
22    }
23}