pub struct QueryPlanCache { /* private fields */ }Expand description
A simple LRU query-plan cache with O(n) eviction.
This is deliberately kept dependency-free (no lru crate, no SciRS2).
The access order vector has the most-recently-used entry at the front
(index 0) and the least-recently-used at the back.
For the high-throughput LRU cache backed by the lru crate, see
LruQueryPlanCache.
Implementations§
Source§impl QueryPlanCache
impl QueryPlanCache
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new cache that can hold at most max_size plans.
If max_size is 0 it is treated as 1 to avoid degenerate behaviour.
Sourcepub fn get(&mut self, query_hash: u64) -> Option<&QueryPlan>
pub fn get(&mut self, query_hash: u64) -> Option<&QueryPlan>
Retrieve the plan for query_hash.
On a hit the entry is moved to the front of the access-order list and
stats.hits is incremented. On a miss stats.misses is incremented.
Sourcepub fn insert(&mut self, plan: QueryPlan)
pub fn insert(&mut self, plan: QueryPlan)
Insert a plan into the cache.
If the cache is at capacity, evict_lru is called first. The new
entry is placed at the front of the access-order list.
Sourcepub fn evict_lru(&mut self) -> Option<QueryPlan>
pub fn evict_lru(&mut self) -> Option<QueryPlan>
Remove and return the least-recently-used plan (the one at the back of
the access-order list). Increments stats.evictions.
Returns None if the cache is empty.
Sourcepub fn invalidate(&mut self, query_hash: u64) -> bool
pub fn invalidate(&mut self, query_hash: u64) -> bool
Remove a specific plan by hash. Returns true if it existed.
Sourcepub fn stats(&self) -> &PlanCacheStats
pub fn stats(&self) -> &PlanCacheStats
Return a snapshot of the current statistics.
Auto Trait Implementations§
impl Freeze for QueryPlanCache
impl RefUnwindSafe for QueryPlanCache
impl Send for QueryPlanCache
impl Sync for QueryPlanCache
impl Unpin for QueryPlanCache
impl UnsafeUnpin for QueryPlanCache
impl UnwindSafe for QueryPlanCache
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