pub struct CoreResultCache { /* private fields */ }Expand description
Thread-safe core-level SPARQL query result cache.
Construct with CoreResultCache::new and use put / get for caching.
§Example
use oxirs_core::cache::result_cache::{CoreResultCache, CoreCacheKey};
use std::time::Duration;
let cache = CoreResultCache::new(1000, Duration::from_secs(300));
let key = CoreCacheKey::new("my_dataset", "SELECT * WHERE { ?s ?p ?o }");
cache.put(key.clone(), vec![], vec!["http://p/name".to_string()]);
assert!(cache.get(&key).is_some());Implementations§
Source§impl CoreResultCache
impl CoreResultCache
Sourcepub fn new(capacity: usize, ttl: Duration) -> Self
pub fn new(capacity: usize, ttl: Duration) -> Self
Create a new cache with capacity entries and a default TTL.
Sourcepub fn get(&self, key: &CoreCacheKey) -> Option<Vec<HashMap<String, String>>>
pub fn get(&self, key: &CoreCacheKey) -> Option<Vec<HashMap<String, String>>>
Retrieve a cached result.
Returns None on a miss (including expired entries, which are then removed).
On a hit, last_accessed and hit_count are updated and the entry is moved to the
MRU position.
Sourcepub fn put(
&self,
key: CoreCacheKey,
rows: Vec<HashMap<String, String>>,
predicates: Vec<String>,
)
pub fn put( &self, key: CoreCacheKey, rows: Vec<HashMap<String, String>>, predicates: Vec<String>, )
Store a query result in the cache.
If the cache is at capacity, the least-recently-used entry is evicted first. Expired
entries are also purged opportunistically on every put.
Sourcepub fn put_with_ttl(
&self,
key: CoreCacheKey,
rows: Vec<HashMap<String, String>>,
predicates: Vec<String>,
ttl: Duration,
)
pub fn put_with_ttl( &self, key: CoreCacheKey, rows: Vec<HashMap<String, String>>, predicates: Vec<String>, ttl: Duration, )
Like CoreResultCache::put but with a custom TTL for this entry.
Sourcepub fn invalidate_dataset(&self, dataset_id: &str) -> usize
pub fn invalidate_dataset(&self, dataset_id: &str) -> usize
Invalidate all entries for a given dataset.
Returns the number of entries removed.
Sourcepub fn invalidate_predicate(&self, dataset_id: &str, predicate: &str) -> usize
pub fn invalidate_predicate(&self, dataset_id: &str, predicate: &str) -> usize
Invalidate all entries for a dataset that accessed a specific predicate.
Returns the number of entries removed.
Sourcepub fn invalidate_on_delta(
&self,
dataset_id: &str,
deltas: &[TripleDelta],
) -> usize
pub fn invalidate_on_delta( &self, dataset_id: &str, deltas: &[TripleDelta], ) -> usize
Invalidate cache entries affected by the given triple deltas.
An entry is considered affected if:
- Its
accessed_predicateslist is empty (wildcard), or - Any of the delta predicates appears in the entry’s
accessed_predicates.
Returns the number of entries removed.
Sourcepub fn hit_rate(&self) -> f64
pub fn hit_rate(&self) -> f64
Return the cache hit rate in [0, 1].
Returns 0.0 if no requests have been made yet.
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Return the number of entries currently in the cache (including potentially expired ones that have not yet been purged).
Sourcepub fn miss_count(&self) -> u64
pub fn miss_count(&self) -> u64
Return the raw miss count.
Auto Trait Implementations§
impl Freeze for CoreResultCache
impl RefUnwindSafe for CoreResultCache
impl Send for CoreResultCache
impl Sync for CoreResultCache
impl Unpin for CoreResultCache
impl UnsafeUnpin for CoreResultCache
impl UnwindSafe for CoreResultCache
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> 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 more