pub struct PreparedStatementCache { /* private fields */ }Expand description
A cache for prepared statements.
Tracks which SQL strings have been prepared so we emit a trace!
for hits vs. misses. Eviction is true LRU via lru::LruCache —
when the cache reaches max_size the least-recently-used entry is
dropped on the next insert.
The cache is keyed on the SQL string; the actual Statement is
fetched from client.prepare_cached on every call (deadpool reuses
its own per-connection cache).
Implementations§
Source§impl PreparedStatementCache
impl PreparedStatementCache
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new statement cache with the given maximum size.
max_size of 0 is treated as 1 to satisfy NonZeroUsize.
Sourcepub async fn get_or_prepare(
&self,
client: &Object,
sql: &str,
) -> PgResult<Statement>
pub async fn get_or_prepare( &self, client: &Object, sql: &str, ) -> PgResult<Statement>
Get or prepare a statement for the given SQL.
Sourcepub async fn get_or_prepare_in_txn<'a>(
&self,
txn: &Transaction<'a>,
sql: &str,
) -> PgResult<Statement>
pub async fn get_or_prepare_in_txn<'a>( &self, txn: &Transaction<'a>, sql: &str, ) -> PgResult<Statement>
Get or prepare a statement within a transaction.
Auto Trait Implementations§
impl !Freeze for PreparedStatementCache
impl RefUnwindSafe for PreparedStatementCache
impl Send for PreparedStatementCache
impl Sync for PreparedStatementCache
impl Unpin for PreparedStatementCache
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more