pub struct StatementCache { /* private fields */ }Expand description
Client-side statement cache using LRU eviction
The cache stores prepared statements keyed by their SQL text. When a statement is retrieved from cache, its cursor ID is preserved, allowing Oracle to skip parsing and use the cached server cursor.
§Example
// Statement caching is automatic when enabled via config
let mut config = Config::new("localhost", 1521, "FREEPDB1", "user", "pass");
config.set_stmtcachesize(20); // Enable with 20 statement cache
let conn = Connection::connect_with_config(config).await?;
// First call: parses SQL, gets cursor_id from Oracle
conn.query("SELECT * FROM users WHERE id = :1", &[Value::Integer(1)]).await?;
// Second call: reuses cached cursor, no re-parsing!
conn.query("SELECT * FROM users WHERE id = :1", &[Value::Integer(2)]).await?;Implementations§
Source§impl StatementCache
impl StatementCache
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new statement cache with the given maximum size
A size of 0 effectively disables caching.
Sourcepub fn get(&mut self, sql: &str) -> Option<Statement>
pub fn get(&mut self, sql: &str) -> Option<Statement>
Get a statement from the cache, if available
Returns a clone of the cached statement with preserved cursor_id and metadata. If the cached statement is already in use, returns a fresh statement. Updates LRU ordering on hit.
Sourcepub fn put(&mut self, sql: String, statement: Statement)
pub fn put(&mut self, sql: String, statement: Statement)
Store a statement in the cache
DDL statements are never cached. If the cache is full, the least recently used statement is evicted and its cursor ID is queued for closing.
Sourcepub fn return_statement(&mut self, sql: &str)
pub fn return_statement(&mut self, sql: &str)
Return a statement to the cache after use
This marks the statement as no longer in use so it can be reused.
Sourcepub fn take_cursors_to_close(&mut self) -> Vec<u16>
pub fn take_cursors_to_close(&mut self) -> Vec<u16>
Get and clear the list of cursor IDs that need to be closed
These cursor IDs should be sent to the server on the next message.