pub struct QueryCache { /* private fields */ }Expand description
An in-memory cache for memoized query results.
Enable it on a pool with DbBuilder::query_cache
and opt queries in with Select::memoize:
let db = Db::builder().query_cache(10_000).connect(url).await?;
let admins = User::filter(User::ROLE.eq("admin"))
.memoize(Duration::from_secs(30))
.all(&db)
.await?;Entries expire after their time-to-live, and every write that rok-db
performs on a table (insert, save, upsert, delete, bulk update/delete —
including inside transactions, again on commit) invalidates that table’s
entries. Changes rok-db can’t see are not tracked: writes from other
processes, raw SQL that doesn’t declare
Raw::invalidates, and rows changed by
ON DELETE CASCADE, ON UPDATE actions or triggers on other tables.
For those, call invalidate yourself or rely on a
short TTL.
The cache is local to the process; cloning it is cheap and shares state.
Implementations§
Source§impl QueryCache
impl QueryCache
Sourcepub fn new(capacity: usize) -> QueryCache
pub fn new(capacity: usize) -> QueryCache
A cache holding at most capacity query results.
Sourcepub fn invalidate(&self, table: &str)
pub fn invalidate(&self, table: &str)
Drop every cached result read from table (on every instance, when
shared invalidation is enabled).
Source§impl QueryCache
impl QueryCache
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Hit/miss counters and the current size.
Trait Implementations§
Source§impl Clone for QueryCache
impl Clone for QueryCache
Source§fn clone(&self) -> QueryCache
fn clone(&self) -> QueryCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for QueryCache
impl RefUnwindSafe for QueryCache
impl Send for QueryCache
impl Sync for QueryCache
impl Unpin for QueryCache
impl UnsafeUnpin for QueryCache
impl UnwindSafe for QueryCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<M> InScope<(M, ()), Here> for M
impl<M, Rest, N> InScope<(M, (Rest, N)), Last> for N
impl<X, M, Rest, N, I> InScope<(M, (Rest, N)), There<I>> for X
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more