pub struct ValidationCache { /* private fields */ }Expand description
Thread-safe, TTL-aware validation result cache.
§Usage
use oxirs_shacl::cache::validation_cache::{ValidationCache, ValidationCacheKey, CachedValidationResult};
use std::time::Duration;
let cache = ValidationCache::new(1000, Duration::from_secs(300));
let key = ValidationCacheKey::new("http://ex/Alice", "http://ex/PersonShape", 42);
let entry = CachedValidationResult::new(
"http://ex/Alice",
"http://ex/PersonShape",
true,
vec![],
Duration::from_secs(300),
);
cache.put(key.clone(), entry);
assert!(cache.get(&key).is_some());Implementations§
Source§impl ValidationCache
impl ValidationCache
Sourcepub fn new(max_entries: usize, ttl: Duration) -> Self
pub fn new(max_entries: usize, ttl: Duration) -> Self
Create a new cache.
max_entries— maximum number of entries before LRU eviction kicks inttl— default time-to-live for new entries
Sourcepub fn get(&self, key: &ValidationCacheKey) -> Option<CachedValidationResult>
pub fn get(&self, key: &ValidationCacheKey) -> Option<CachedValidationResult>
Look up a validation result.
Returns None if the key is not present or the entry is stale.
Stale entries are removed on lookup.
Sourcepub fn put(&self, key: ValidationCacheKey, result: CachedValidationResult)
pub fn put(&self, key: ValidationCacheKey, result: CachedValidationResult)
Insert or update a validation result.
If the cache is at capacity, the least-recently-used entry is evicted first.
Sourcepub fn invalidate_node(&self, focus_node: &str) -> usize
pub fn invalidate_node(&self, focus_node: &str) -> usize
Invalidate all cache entries whose focus_node matches the given string.
Returns the number of entries removed.
Sourcepub fn invalidate_triple(&self, triple_key: &str) -> usize
pub fn invalidate_triple(&self, triple_key: &str) -> usize
Invalidate all cache entries that accessed the given triple during validation.
Returns the number of entries removed.
Sourcepub fn evict_stale(&self) -> usize
pub fn evict_stale(&self) -> usize
Remove all stale (TTL-expired) entries.
Returns the number of entries removed.
Sourcepub fn raw_size(&self) -> usize
pub fn raw_size(&self) -> usize
Total number of entries (including stale ones not yet evicted).
Sourcepub fn hit_rate(&self) -> f64
pub fn hit_rate(&self) -> f64
Cache hit rate (hits / (hits + misses)), or 0.0 when no lookups have occurred.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Returns a snapshot of cache statistics.
Sourcepub fn default_ttl(&self) -> Duration
pub fn default_ttl(&self) -> Duration
Return the default TTL for this cache instance.
Trait Implementations§
Source§impl Clone for ValidationCache
impl Clone for ValidationCache
Source§fn clone(&self) -> ValidationCache
fn clone(&self) -> ValidationCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ValidationCache
impl RefUnwindSafe for ValidationCache
impl Send for ValidationCache
impl Sync for ValidationCache
impl Unpin for ValidationCache
impl UnsafeUnpin for ValidationCache
impl UnwindSafe for ValidationCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.