pub struct StatementCache { /* private fields */ }Expand description
LRU cache for prepared statements.
This cache automatically evicts the least recently used statements when
the maximum capacity is reached. Evicted statements should have their
server-side handles released via sp_unprepare.
Implementations§
Source§impl StatementCache
impl StatementCache
Sourcepub fn with_default_size() -> Self
pub fn with_default_size() -> Self
Create a new statement cache with the default maximum size.
Sourcepub fn get(&mut self, sql: &str) -> Option<i32>
pub fn get(&mut self, sql: &str) -> Option<i32>
Look up a prepared statement by SQL text.
Returns Some(handle) if the statement is cached, None otherwise.
This updates the LRU order.
Sourcepub fn peek(&self, sql: &str) -> Option<&PreparedStatement>
pub fn peek(&self, sql: &str) -> Option<&PreparedStatement>
Peek at a prepared statement without updating LRU order.
Sourcepub fn insert(&mut self, stmt: PreparedStatement) -> Option<PreparedStatement>
pub fn insert(&mut self, stmt: PreparedStatement) -> Option<PreparedStatement>
Insert a prepared statement into the cache.
Returns the evicted statement if one was removed due to capacity.
Sourcepub fn remove(&mut self, sql: &str) -> Option<PreparedStatement>
pub fn remove(&mut self, sql: &str) -> Option<PreparedStatement>
Remove a prepared statement from the cache.
Returns the removed statement if it was present.
Sourcepub fn clear(&mut self) -> impl Iterator<Item = PreparedStatement> + '_
pub fn clear(&mut self) -> impl Iterator<Item = PreparedStatement> + '_
Clear all cached statements.
Returns an iterator over all removed statements.
The caller should call sp_unprepare for each returned statement.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset cache statistics.