pub struct DbQuery<T, C = PostcardCodec>where
C: CacheCodec,{ /* private fields */ }Expand description
A cacheable database query descriptor.
The descriptor is deliberately explicit: callers choose the key, tags, and
TTL that match their freshness model. An operation name is optional and used
only for diagnostics. fetch_with executes the supplied loader only on a
cache miss.
Implementations§
Source§impl<T, C> DbQuery<T, C>where
C: CacheCodec,
impl<T, C> DbQuery<T, C>where
C: CacheCodec,
Sourcepub fn with_name(self, name: impl Into<String>) -> DbQuery<T, C>
pub fn with_name(self, name: impl Into<String>) -> DbQuery<T, C>
Set or replace the diagnostic operation name.
Sourcepub fn physical_key(&self) -> Option<String>
pub fn physical_key(&self) -> Option<String>
Return the physical cache key, including the adapter namespace.
Return the configured tags.
Sourcepub fn key(self, key: impl Into<String>) -> DbQuery<T, C>
pub fn key(self, key: impl Into<String>) -> DbQuery<T, C>
Set the logical cache key for this query result.
Sourcepub fn key_builder(self, key: CacheKeyBuilder) -> DbQuery<T, C>
pub fn key_builder(self, key: CacheKeyBuilder) -> DbQuery<T, C>
Set the logical cache key from a segmented key builder.
Add several invalidation tags.
Sourcepub fn tag_set(self, tags: TagSet) -> DbQuery<T, C>
pub fn tag_set(self, tags: TagSet) -> DbQuery<T, C>
Replace invalidation tags from a reusable TagSet.
Sourcepub async fn fetch_with<E, F, Fut>(self, loader: F) -> Result<T, DbCacheError>
pub async fn fetch_with<E, F, Fut>(self, loader: F) -> Result<T, DbCacheError>
Fetch a cached value or run the supplied database loader on miss.
The loader is intentionally caller-supplied so the database library remains responsible for pools, transactions, compile-time checked queries, and row mapping. HydraCache owns only the cache boundary.
Trait Implementations§
Auto Trait Implementations§
impl<T, C> Freeze for DbQuery<T, C>
impl<T, C = PostcardCodec> !RefUnwindSafe for DbQuery<T, C>
impl<T, C> Send for DbQuery<T, C>
impl<T, C> Sync for DbQuery<T, C>
impl<T, C> Unpin for DbQuery<T, C>
impl<T, C> UnsafeUnpin for DbQuery<T, C>
impl<T, C = PostcardCodec> !UnwindSafe for DbQuery<T, C>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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