pub struct QueryCachePolicy { /* private fields */ }Expand description
Reusable cache metadata for one database query result.
QueryCachePolicy contains the database-neutral parts of query result
caching: diagnostic name, logical key, invalidation tags, and optional TTL.
It is intentionally independent of SQLx, Diesel, SeaORM, or any other
database client.
§Example
use std::time::Duration;
use hydracache_db::QueryCachePolicy;
let policy = QueryCachePolicy::named("load-user")
.key("user:42")
.tag("user:42")
.ttl(Duration::from_secs(60));
assert_eq!(policy.name(), Some("load-user"));
assert_eq!(policy.key_value(), Some("user:42"));
assert_eq!(policy.tags_value(), &["user:42".to_owned()]);
assert_eq!(policy.ttl_value(), Some(Duration::from_secs(60)));The query_cache_policy! macro provides a
shorter declarative form when the policy is known at the call site.
Implementations§
Source§impl QueryCachePolicy
impl QueryCachePolicy
Sourcepub fn new() -> QueryCachePolicy
pub fn new() -> QueryCachePolicy
Create an empty cache policy.
Sourcepub fn named(name: impl Into<String>) -> QueryCachePolicy
pub fn named(name: impl Into<String>) -> QueryCachePolicy
Create a cache policy with a diagnostic operation name.
Return configured invalidation tags.
Sourcepub fn with_name(self, name: impl Into<String>) -> QueryCachePolicy
pub fn with_name(self, name: impl Into<String>) -> QueryCachePolicy
Set or replace the diagnostic operation name.
Sourcepub fn key(self, key: impl Into<String>) -> QueryCachePolicy
pub fn key(self, key: impl Into<String>) -> QueryCachePolicy
Set the logical cache key.
Sourcepub fn key_builder(self, key: CacheKeyBuilder) -> QueryCachePolicy
pub fn key_builder(self, key: CacheKeyBuilder) -> QueryCachePolicy
Set the logical cache key from a segmented key builder.
Sourcepub fn for_entity(
self,
kind: impl ToString,
id: impl ToString,
) -> QueryCachePolicy
pub fn for_entity( self, kind: impl ToString, id: impl ToString, ) -> QueryCachePolicy
Set the logical key and add the same entity invalidation tag.
Sourcepub fn for_cache_entity<T>(self, id: <T as CacheEntity>::Id) -> QueryCachePolicywhere
T: CacheEntity,
pub fn for_cache_entity<T>(self, id: <T as CacheEntity>::Id) -> QueryCachePolicywhere
T: CacheEntity,
Set the logical key and tags from CacheEntity metadata.
Sourcepub fn collection(self, name: impl ToString) -> QueryCachePolicy
pub fn collection(self, name: impl ToString) -> QueryCachePolicy
Set the logical key and invalidation tag for a collection result.
Sourcepub fn tag(self, tag: impl Into<String>) -> QueryCachePolicy
pub fn tag(self, tag: impl Into<String>) -> QueryCachePolicy
Add one invalidation tag.
Sourcepub fn collection_tag(self, name: impl ToString) -> QueryCachePolicy
pub fn collection_tag(self, name: impl ToString) -> QueryCachePolicy
Add a collection invalidation tag from one escaped key segment.
Add several invalidation tags.
Sourcepub fn tag_set(self, tags: TagSet) -> QueryCachePolicy
pub fn tag_set(self, tags: TagSet) -> QueryCachePolicy
Replace invalidation tags from a reusable TagSet.
Sourcepub fn ttl(self, ttl: Duration) -> QueryCachePolicy
pub fn ttl(self, ttl: Duration) -> QueryCachePolicy
Set a per-entry TTL.
Trait Implementations§
Source§impl Clone for QueryCachePolicy
impl Clone for QueryCachePolicy
Source§fn clone(&self) -> QueryCachePolicy
fn clone(&self) -> QueryCachePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QueryCachePolicy
impl Debug for QueryCachePolicy
Source§impl Default for QueryCachePolicy
impl Default for QueryCachePolicy
Source§fn default() -> QueryCachePolicy
fn default() -> QueryCachePolicy
impl Eq for QueryCachePolicy
Source§impl PartialEq for QueryCachePolicy
impl PartialEq for QueryCachePolicy
Source§fn eq(&self, other: &QueryCachePolicy) -> bool
fn eq(&self, other: &QueryCachePolicy) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for QueryCachePolicy
Auto Trait Implementations§
impl Freeze for QueryCachePolicy
impl RefUnwindSafe for QueryCachePolicy
impl Send for QueryCachePolicy
impl Sync for QueryCachePolicy
impl Unpin for QueryCachePolicy
impl UnsafeUnpin for QueryCachePolicy
impl UnwindSafe for QueryCachePolicy
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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