StatementCache

Struct StatementCache 

Source
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

Source

pub fn new(max_size: usize) -> Self

Create a new statement cache with the given maximum size

A size of 0 effectively disables caching.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Clear all cached statements

All cursor IDs are queued for closing. This should be called when the session changes (e.g., DRCP session switch).

Source

pub fn len(&self) -> usize

Get the current number of cached statements

Source

pub fn is_empty(&self) -> bool

Check if the cache is empty

Source

pub fn max_size(&self) -> usize

Get the maximum cache size

Trait Implementations§

Source§

impl Debug for StatementCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more