#[non_exhaustive]pub struct StatementCache { /* private fields */ }Expand description
A least-recently-used (LRU) cache for prepared statements.
The cache is keyed by SQL text. When a statement is looked up that is not in the cache, it is prepared on the server and stored. If the cache is at capacity, the least-recently-used statement is evicted (closed on the server) before the new one is inserted.
Implementations§
Source§impl StatementCache
impl StatementCache
Sourcepub fn get(&mut self, sql: &str) -> Option<&PreparedStatement>
pub fn get(&mut self, sql: &str) -> Option<&PreparedStatement>
Look up a prepared statement by SQL text.
Returns Some if the statement is cached. The statement is moved to
the front of the 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.
If the cache is at capacity, the LRU entry is removed from the map (but not closed on the server — the caller must do that if needed). Returns the evicted statement, if any.
Sourcepub fn remove(&mut self, sql: &str) -> Option<PreparedStatement>
pub fn remove(&mut self, sql: &str) -> Option<PreparedStatement>
Remove a statement from the cache by SQL text.
Returns the removed statement, if any.
Sourcepub fn clear(&mut self) -> Vec<PreparedStatement>
pub fn clear(&mut self) -> Vec<PreparedStatement>
Clear all entries from the cache.
Returns the evicted statements. The caller is responsible for closing them on the server if needed.
Trait Implementations§
Source§impl Clone for StatementCache
impl Clone for StatementCache
Source§fn clone(&self) -> StatementCache
fn clone(&self) -> StatementCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more