pub struct PreparedStatementCache { /* private fields */ }Expand description
Thread-safe cache for prepared statements with LRU eviction
Implementations§
Source§impl PreparedStatementCache
impl PreparedStatementCache
Sourcepub fn default_cache() -> Self
pub fn default_cache() -> Self
Create a default cache (1000 entries)
Sourcepub fn get(&self, sql: &str) -> Option<Arc<PreparedStatement>>
pub fn get(&self, sql: &str) -> Option<Arc<PreparedStatement>>
Get a prepared statement from cache (updates LRU order)
Sourcepub fn get_or_prepare(
&self,
sql: &str,
) -> Result<Arc<PreparedStatement>, PreparedStatementError>
pub fn get_or_prepare( &self, sql: &str, ) -> Result<Arc<PreparedStatement>, PreparedStatementError>
Get or insert a prepared statement
If the SQL is in cache, returns the cached statement. Otherwise, parses the SQL, caches it, and returns the new statement. Uses double-checked locking to avoid duplicate parsing.
Sourcepub fn get_or_prepare_arena(
&self,
sql: &str,
) -> Result<Arc<ArenaPreparedStatement>, ArenaParseError>
pub fn get_or_prepare_arena( &self, sql: &str, ) -> Result<Arc<ArenaPreparedStatement>, ArenaParseError>
Get or insert an arena-based prepared statement
This method returns an arena-allocated SELECT statement for optimal
performance. It’s only for SELECT statements - other statement types
will fail with UnsupportedStatement.
Arena statements provide:
- Better cache locality (contiguous memory)
- Potentially lower allocation overhead
- Direct use with arena-based execution paths
For non-SELECT statements, use get_or_prepare instead.
Sourcepub fn get_arena(&self, sql: &str) -> Option<Arc<ArenaPreparedStatement>>
pub fn get_arena(&self, sql: &str) -> Option<Arc<ArenaPreparedStatement>>
Get an arena-based prepared statement if it exists in cache
Sourcepub fn invalidate_table(&self, table: &str)
pub fn invalidate_table(&self, table: &str)
Invalidate all statements referencing a table
Sourcepub fn stats(&self) -> PreparedStatementCacheStats
pub fn stats(&self) -> PreparedStatementCacheStats
Get cache statistics
Auto Trait Implementations§
impl !Freeze for PreparedStatementCache
impl RefUnwindSafe for PreparedStatementCache
impl Send for PreparedStatementCache
impl Sync for PreparedStatementCache
impl Unpin for PreparedStatementCache
impl UnwindSafe for PreparedStatementCache
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> 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