pub struct VerificationCache { /* private fields */ }Expand description
Bounded in-memory cache for verification outcomes.
§Examples
use keyhog_verifier::cache::VerificationCache;
use std::time::Duration;
let cache = VerificationCache::new(Duration::from_secs(60));
assert!(cache.is_empty());Implementations§
Source§impl VerificationCache
impl VerificationCache
Sourcepub fn new(ttl: Duration) -> Self
pub fn new(ttl: Duration) -> Self
Create a new cache with the given TTL.
§Examples
use keyhog_verifier::cache::VerificationCache;
use std::time::Duration;
let cache = VerificationCache::new(Duration::from_secs(60));
assert!(cache.is_empty());Sourcepub fn with_max_entries(ttl: Duration, max_entries: usize) -> Self
pub fn with_max_entries(ttl: Duration, max_entries: usize) -> Self
Create a new cache with the given TTL and an explicit size bound.
§Examples
use keyhog_verifier::cache::VerificationCache;
use std::time::Duration;
let cache = VerificationCache::with_max_entries(Duration::from_secs(60), 32);
assert!(cache.is_empty());Sourcepub fn default_ttl() -> Self
pub fn default_ttl() -> Self
Default cache: 5 minute TTL.
§Examples
use keyhog_verifier::cache::VerificationCache;
let cache = VerificationCache::default_ttl();
assert!(cache.is_empty());Sourcepub fn get(
&self,
credential: &str,
detector_id: &str,
) -> Option<(VerificationResult, HashMap<String, String>)>
pub fn get( &self, credential: &str, detector_id: &str, ) -> Option<(VerificationResult, HashMap<String, String>)>
Look up a cached result.
§Examples
use keyhog_core::VerificationResult;
use keyhog_verifier::cache::VerificationCache;
use std::collections::HashMap;
use std::time::Duration;
let cache = VerificationCache::new(Duration::from_secs(60));
cache.put("secret", "detector", VerificationResult::Live, HashMap::new());
assert!(cache.get("secret", "detector").is_some());Sourcepub fn put(
&self,
credential: &str,
detector_id: &str,
result: VerificationResult,
metadata: HashMap<String, String>,
)
pub fn put( &self, credential: &str, detector_id: &str, result: VerificationResult, metadata: HashMap<String, String>, )
Store a verification result.
§Examples
use keyhog_core::VerificationResult;
use keyhog_verifier::cache::VerificationCache;
use std::collections::HashMap;
use std::time::Duration;
let cache = VerificationCache::new(Duration::from_secs(60));
cache.put("secret", "detector", VerificationResult::Live, HashMap::new());
assert_eq!(cache.len(), 1);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of cached entries.
§Examples
use keyhog_verifier::cache::VerificationCache;
use std::time::Duration;
let cache = VerificationCache::new(Duration::from_secs(60));
assert_eq!(cache.len(), 0);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true when the cache contains no live entries.
§Examples
use keyhog_verifier::cache::VerificationCache;
use std::time::Duration;
let cache = VerificationCache::new(Duration::from_secs(60));
assert!(cache.is_empty());Sourcepub fn evict_expired(&self)
pub fn evict_expired(&self)
Evict expired entries.
§Examples
use keyhog_verifier::cache::VerificationCache;
use std::time::Duration;
let cache = VerificationCache::new(Duration::from_secs(60));
cache.evict_expired();
assert!(cache.is_empty());Auto Trait Implementations§
impl !Freeze for VerificationCache
impl !RefUnwindSafe for VerificationCache
impl Send for VerificationCache
impl Sync for VerificationCache
impl Unpin for VerificationCache
impl UnsafeUnpin for VerificationCache
impl UnwindSafe for VerificationCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more