pub struct QueryCache { /* private fields */ }Expand description
A thread-safe cache for SQL queries.
Uses a simple LRU-like eviction strategy when the cache is full.
Implementations§
Source§impl QueryCache
impl QueryCache
Sourcepub fn insert(&self, key: impl Into<QueryKey>, sql: impl Into<String>)
pub fn insert(&self, key: impl Into<QueryKey>, sql: impl Into<String>)
Insert a query into the cache.
Sourcepub fn insert_with_params(
&self,
key: impl Into<QueryKey>,
sql: impl Into<String>,
param_count: usize,
)
pub fn insert_with_params( &self, key: impl Into<QueryKey>, sql: impl Into<String>, param_count: usize, )
Insert a query with known parameter count.
Sourcepub fn get_entry(&self, key: impl Into<QueryKey>) -> Option<CachedQuery>
pub fn get_entry(&self, key: impl Into<QueryKey>) -> Option<CachedQuery>
Get a cached query entry (includes metadata).
Sourcepub fn get_or_insert<F>(&self, key: impl Into<QueryKey>, f: F) -> String
pub fn get_or_insert<F>(&self, key: impl Into<QueryKey>, f: F) -> String
Get or compute a query.
If the query is cached, returns the cached version. Otherwise, computes it using the provided function and caches it.
Sourcepub fn remove(&self, key: impl Into<QueryKey>) -> Option<String>
pub fn remove(&self, key: impl Into<QueryKey>) -> Option<String>
Remove a query from the cache.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics.
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset cache statistics.
Trait Implementations§
Source§impl Debug for QueryCache
impl Debug for QueryCache
Auto Trait Implementations§
impl !Freeze for QueryCache
impl RefUnwindSafe for QueryCache
impl Send for QueryCache
impl Sync for QueryCache
impl Unpin for QueryCache
impl UnwindSafe for QueryCache
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