pub struct GqlQueryCache { /* private fields */ }Expand description
Thread-safe, schema-aware GraphQL query result cache.
Supports:
- LRU eviction once the entry count reaches
max_entries. - TTL-based expiry (checked lazily on
getand explicitly viaevict_expired). - Bulk invalidation by graph IRI or tenant ID.
- Hit/miss rate statistics.
Implementations§
Source§impl GqlQueryCache
impl GqlQueryCache
Sourcepub fn new(max_entries: usize, default_ttl: Duration) -> Self
pub fn new(max_entries: usize, default_ttl: Duration) -> Self
Create a new cache.
max_entries: Maximum number of entries before LRU eviction kicks in.default_ttl: TTL used whenputdoes not specify a custom TTL.
Sourcepub fn get(&self, key: &CacheKey) -> Option<String>
pub fn get(&self, key: &CacheKey) -> Option<String>
Look up a cached response.
Returns Some(json) on a cache hit (updating the hit counter and
LRU order). Returns None on a miss or if the entry has expired
(expired entries are removed eagerly).
Sourcepub fn put(
&self,
key: CacheKey,
response: String,
graphs: Vec<String>,
predicates: Vec<String>,
) -> bool
pub fn put( &self, key: CacheKey, response: String, graphs: Vec<String>, predicates: Vec<String>, ) -> bool
Store a response in the cache with the default TTL.
graphs: RDF graph IRIs that were read when generating this response.predicates: RDF predicates that were read.
Returns true if the entry was inserted, false if the mutex was
unavailable (should not happen under normal conditions).
Sourcepub fn put_with_ttl(
&self,
key: CacheKey,
response: String,
graphs: Vec<String>,
predicates: Vec<String>,
ttl: Duration,
) -> bool
pub fn put_with_ttl( &self, key: CacheKey, response: String, graphs: Vec<String>, predicates: Vec<String>, ttl: Duration, ) -> bool
Store a response with an explicit TTL override.
Sourcepub fn invalidate_by_graph(&self, graph: &str) -> usize
pub fn invalidate_by_graph(&self, graph: &str) -> usize
Invalidate all cache entries that read from graph.
Returns the number of entries removed.
Sourcepub fn invalidate_by_tenant(&self, tenant_id: &str) -> usize
pub fn invalidate_by_tenant(&self, tenant_id: &str) -> usize
Invalidate all cache entries belonging to tenant_id.
Returns the number of entries removed.
Sourcepub fn evict_expired(&self) -> usize
pub fn evict_expired(&self) -> usize
Remove all expired entries from the cache.
Returns the number of entries removed.
Sourcepub fn clear(&self) -> usize
pub fn clear(&self) -> usize
Clear all entries from the cache.
Returns the number of entries removed.
Sourcepub fn hit_rate(&self) -> f64
pub fn hit_rate(&self) -> f64
Returns the cache hit rate as a value in [0.0, 1.0].
Returns 0.0 if no requests have been made yet.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Returns cumulative hit/miss/eviction counters.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GqlQueryCache
impl RefUnwindSafe for GqlQueryCache
impl Send for GqlQueryCache
impl Sync for GqlQueryCache
impl Unpin for GqlQueryCache
impl UnsafeUnpin for GqlQueryCache
impl UnwindSafe for GqlQueryCache
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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