pub struct QueryCache<B = ()> { /* private fields */ }Expand description
Query cache for parsed SQL statements
Provides thread-safe caching of parsed SQL queries to avoid the overhead of parsing the same query multiple times.
Implementations§
Source§impl<B: Default> QueryCache<B>
impl<B: Default> QueryCache<B>
Sourcepub fn default_sized() -> Self
pub fn default_sized() -> Self
Create a new query cache with default size
Sourcepub fn get(&self, query: &str) -> Option<CachedPlanRef<B>>
pub fn get(&self, query: &str) -> Option<CachedPlanRef<B>>
Get a cached plan for a query if available
Returns a cheap Arc clone of the cached statement and metadata. The Statement is immutable and shared via Arc.
A hit updates recency and usage so eviction reflects actual access.
Sourcepub fn put(
&self,
query: &str,
statement: Arc<Statement>,
_has_params: bool,
_param_count: usize,
) -> CachedPlanRef<B>
pub fn put( &self, query: &str, statement: Arc<Statement>, _has_params: bool, _param_count: usize, ) -> CachedPlanRef<B>
Add a plan to the cache
Returns a lightweight reference to the cached plan (CachedPlanRef). This avoids cloning SmartStrings since callers only need the statement and compiled execution state.
Sourcepub fn invalidate_table(&self, table_name: &str)
pub fn invalidate_table(&self, table_name: &str)
Invalidate all cached plans that reference a specific table Called after DDL operations (ALTER TABLE, DROP TABLE, etc.)
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics
Trait Implementations§
Auto Trait Implementations§
impl<B = ()> !Freeze for QueryCache<B>
impl<B> RefUnwindSafe for QueryCache<B>where
RwLock<HashMap<SmartString, CachedQueryPlan<B>, BuildHasherDefault<FxHasher>>>: RefUnwindSafe,
impl<B> Send for QueryCache<B>
impl<B> Sync for QueryCache<B>
impl<B> Unpin for QueryCache<B>
impl<B> UnsafeUnpin for QueryCache<B>
impl<B> UnwindSafe for QueryCache<B>
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
Mutably borrows from an owned value. Read more