use std::collections::HashSet;
use std::sync::Mutex;
#[derive(Debug, Default)]
pub struct NegativeCache {
inner: Mutex<HashSet<(String, String, String)>>,
}
impl NegativeCache {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn record(&self, source_id: &str, bucket: &str, filename: &str) {
if let Ok(mut guard) = self.inner.lock() {
guard.insert((
source_id.to_string(),
bucket.to_string(),
filename.to_string(),
));
}
}
#[must_use]
pub fn contains(&self, source_id: &str, bucket: &str, filename: &str) -> bool {
self.inner
.lock()
.map(|guard| {
guard.contains(&(
source_id.to_string(),
bucket.to_string(),
filename.to_string(),
))
})
.unwrap_or(false)
}
}
#[cfg(test)]
#[path = "tests/negative_cache.rs"]
mod tests;