pub struct PlanCache { /* private fields */ }Expand description
LRU cache for query plans
Recency is tracked by a monotonic clock counter stamped onto each entry’s
lru_seq on insert and hit, rather than a Vec<String> that had to be
linearly scanned (position() + remove()) on every promotion and removal.
Promotion (the cache-hit hot path) is now O(1) and allocation-free; eviction
picks the entry with the smallest stamp, which is the exact same victim the
old front-of-Vec policy would have chosen for any given access sequence.
Implementations§
Source§impl PlanCache
impl PlanCache
Sourcepub fn new(capacity: usize) -> PlanCache
pub fn new(capacity: usize) -> PlanCache
Create a new plan cache with the given capacity
A capacity of 0 is meaningless and unreachable from every call site today. If one ever appears, the LRU keeps a single entry rather than evicting forever (the pre-#2012 code looped indefinitely on it).
Sourcepub fn peek(&self, key: &str) -> Option<&CachedPlan>
pub fn peek(&self, key: &str) -> Option<&CachedPlan>
Read-only cache probe — no LRU promotion, no mutation.
Use this with a read() lock in the hot query path so concurrent
readers don’t serialize on a write lock. Falls back to None when
the entry is expired or has a pending replan; the caller must then
re-acquire a write() lock and call get() to handle eviction and
miss insertion.
Sourcepub fn get(&mut self, key: &str) -> Option<&CachedPlan>
pub fn get(&mut self, key: &str) -> Option<&CachedPlan>
Get a cached plan by key
Sourcepub fn insert(&mut self, key: String, plan: CachedPlan)
pub fn insert(&mut self, key: String, plan: CachedPlan)
Insert a plan into the cache
Sourcepub fn remove(&mut self, key: &str) -> Option<CachedPlan>
pub fn remove(&mut self, key: &str) -> Option<CachedPlan>
Remove an entry from the cache
Sourcepub fn invalidate<F>(&mut self, predicate: F)
pub fn invalidate<F>(&mut self, predicate: F)
Invalidate entries matching a predicate
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn prune_expired(&mut self)
pub fn prune_expired(&mut self)
Prune expired entries
pub fn record_observation(&mut self, key: &str, rows_scanned: u64)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PlanCache
impl RefUnwindSafe for PlanCache
impl Send for PlanCache
impl Sync for PlanCache
impl Unpin for PlanCache
impl UnsafeUnpin for PlanCache
impl UnwindSafe for PlanCache
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
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::Request