pub struct StatementCache { /* private fields */ }Expand description
LRU-style cache for compiled SQL statements.
Keyed by a u64 hash that callers compute from their query structure.
When the cache exceeds max_size, the least-recently-used entry is evicted.
§Example
use sqlmodel_query::cache::StatementCache;
let mut cache = StatementCache::new(100);
// Cache a compiled query
let sql = cache.get_or_insert(12345, || "SELECT * FROM users WHERE id = $1".to_string());
assert_eq!(sql, "SELECT * FROM users WHERE id = $1");
// Second call returns cached version
let called = std::cell::Cell::new(false);
let sql2 = cache.get_or_insert(12345, || {
called.set(true);
"SELECT * FROM users WHERE id = $1".to_string()
});
assert_eq!(sql2, "SELECT * FROM users WHERE id = $1");
assert!(!called.get());Implementations§
Source§impl StatementCache
impl StatementCache
Trait Implementations§
Source§impl Debug for StatementCache
impl Debug for StatementCache
Auto Trait Implementations§
impl Freeze for StatementCache
impl RefUnwindSafe for StatementCache
impl Send for StatementCache
impl Sync for StatementCache
impl Unpin for StatementCache
impl UnsafeUnpin for StatementCache
impl UnwindSafe for StatementCache
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).