use crate::cache::{CacheKey, ResponseCache};
use crate::transport::RawResponse;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct NullCache;
impl ResponseCache for NullCache {
fn get(&self, _key: &CacheKey) -> Option<RawResponse> {
None
}
fn put(&self, _key: CacheKey, _response: RawResponse) {}
fn clear(&self) {}
fn len(&self) -> Option<usize> {
Some(0)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::registry::Endpoint;
use crate::transport::ResponseKind;
use std::time::Duration;
#[test]
fn never_returns_what_was_stored() {
let cache = NullCache;
let key = CacheKey::new("whois.example", "example.com");
cache.put(
key.clone(),
RawResponse::new(
Endpoint::whois("whois.example"),
ResponseKind::WhoisText,
"record",
Duration::ZERO,
),
);
assert!(cache.get(&key).is_none());
assert_eq!(cache.len(), Some(0));
cache.clear();
}
}