pub struct QueryCache { /* private fields */ }Expand description
Thread-safe LRU cache for server-side query results.
Uses parking_lot::RwLock for efficient concurrent access. Read operations
that result in a cache hit still require a write lock (to update LRU order
and access counters), but the critical section is kept short.
Implementations§
Source§impl QueryCache
impl QueryCache
Sourcepub fn new(
max_entries: usize,
default_ttl: Duration,
max_value_size: usize,
) -> Self
pub fn new( max_entries: usize, default_ttl: Duration, max_value_size: usize, ) -> Self
Create a new QueryCache.
§Arguments
max_entries- maximum number of entries the cache may hold.default_ttl- default time-to-live for cached entries.max_value_size- maximum size (in bytes) of a single cached value.
Sourcepub fn get(&self, key: &CacheKey) -> Option<Vec<u8>>
pub fn get(&self, key: &CacheKey) -> Option<Vec<u8>>
Look up a cached result by cache key.
Returns Some(Vec<u8>) if a non-expired entry exists, otherwise None.
On a hit the entry is promoted to most-recently-used and the hit counter
is incremented. On a miss or expiry the miss counter is incremented.
Sourcepub fn put(&self, key: CacheKey, result: Vec<u8>)
pub fn put(&self, key: CacheKey, result: Vec<u8>)
Store a query result in the cache using the cache’s default TTL.
If the value exceeds max_value_size it is silently rejected. If the
cache is at capacity the least recently used entry is evicted first.
Sourcepub fn put_with_ttl(&self, key: CacheKey, result: Vec<u8>, ttl: Duration)
pub fn put_with_ttl(&self, key: CacheKey, result: Vec<u8>, ttl: Duration)
Store a query result with an explicit TTL and optional collection name.
Sourcepub fn put_with_options(
&self,
key: CacheKey,
result: Vec<u8>,
ttl: Duration,
collection: Option<&str>,
)
pub fn put_with_options( &self, key: CacheKey, result: Vec<u8>, ttl: Duration, collection: Option<&str>, )
Store a query result with an explicit TTL and collection name.
Sourcepub fn invalidate(&self, collection: &str)
pub fn invalidate(&self, collection: &str)
Invalidate all entries belonging to the given collection.
This is the primary write-through invalidation hook: when a PUT, DELETE, or UPDATE operation mutates a collection, call this method with the collection name to ensure stale results are never served.
Sourcepub fn invalidate_all(&self)
pub fn invalidate_all(&self)
Clear the entire cache.
Sourcepub fn stats(&self) -> CacheStatsSnapshot
pub fn stats(&self) -> CacheStatsSnapshot
Return a snapshot of the current cache statistics.
Sourcepub fn resize(&self, new_max: usize)
pub fn resize(&self, new_max: usize)
Resize the cache to a new maximum number of entries.
If the new maximum is smaller than the current number of entries the least recently used entries are evicted until the constraint is met.
Sourcepub fn total_size_bytes(&self) -> usize
pub fn total_size_bytes(&self) -> usize
Total bytes of all cached values.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for QueryCache
impl !RefUnwindSafe for QueryCache
impl Send for QueryCache
impl Sync for QueryCache
impl Unpin for QueryCache
impl UnsafeUnpin for QueryCache
impl UnwindSafe for QueryCache
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.