pub struct InvalidationPlan { /* private fields */ }Expand description
A database-neutral list of cache invalidations staged by repository code.
InvalidationPlan deliberately does not know about SQLx, Diesel, SeaORM, or
any transaction type. Build it while preparing a write, execute the database
transaction in the ORM/client you already use, and call execute only
after commit succeeds. Dropping the plan on rollback leaves cached values
untouched.
§Example
use hydracache::HydraCache;
use hydracache_db::{HydraCacheEntity, InvalidationPlan};
#[derive(HydraCacheEntity)]
#[hydracache(entity = "user", collection = "users")]
struct User {
#[hydracache(id)]
id: i64,
}
let pending = InvalidationPlan::new().cache_entity::<User>(42);
// tx.update_user(42).await?;
// tx.commit().await?;
let report = pending.execute(&cache).await?;
assert_eq!(report.tag_count, 2);Implementations§
Source§impl InvalidationPlan
impl InvalidationPlan
Sourcepub fn new() -> InvalidationPlan
pub fn new() -> InvalidationPlan
Create an empty staged invalidation plan.
Sourcepub fn key(self, key: impl Into<String>) -> InvalidationPlan
pub fn key(self, key: impl Into<String>) -> InvalidationPlan
Stage one physical cache key for removal.
Sourcepub fn keys<I, S>(self, keys: I) -> InvalidationPlan
pub fn keys<I, S>(self, keys: I) -> InvalidationPlan
Stage several physical cache keys for removal.
Sourcepub fn tag(self, tag: impl Into<String>) -> InvalidationPlan
pub fn tag(self, tag: impl Into<String>) -> InvalidationPlan
Stage one invalidation tag.
Stage several invalidation tags.
Sourcepub fn entity<E>(self, id: <E as CacheEntity>::Id) -> InvalidationPlanwhere
E: CacheEntity,
pub fn entity<E>(self, id: <E as CacheEntity>::Id) -> InvalidationPlanwhere
E: CacheEntity,
Stage the entity tag for a CacheEntity id.
Sourcepub fn collection<E>(self) -> InvalidationPlanwhere
E: CacheEntity,
pub fn collection<E>(self) -> InvalidationPlanwhere
E: CacheEntity,
Stage the collection tag for a CacheEntity, if it has one.
Sourcepub fn cache_entity<E>(self, id: <E as CacheEntity>::Id) -> InvalidationPlanwhere
E: CacheEntity,
pub fn cache_entity<E>(self, id: <E as CacheEntity>::Id) -> InvalidationPlanwhere
E: CacheEntity,
Stage both entity and collection tags for a CacheEntity id.
Sourcepub fn key_values(&self) -> impl Iterator<Item = &str>
pub fn key_values(&self) -> impl Iterator<Item = &str>
Staged keys in deterministic order.
Sourcepub fn tag_values(&self) -> impl Iterator<Item = &str>
pub fn tag_values(&self) -> impl Iterator<Item = &str>
Staged tags in deterministic order.
Sourcepub async fn execute<C>(
self,
cache: &HydraCache<C>,
) -> Result<InvalidationReport, CacheError>where
C: CacheCodec,
pub async fn execute<C>(
self,
cache: &HydraCache<C>,
) -> Result<InvalidationReport, CacheError>where
C: CacheCodec,
Execute all staged invalidations against the local cache after commit.
Trait Implementations§
Source§impl Clone for InvalidationPlan
impl Clone for InvalidationPlan
Source§fn clone(&self) -> InvalidationPlan
fn clone(&self) -> InvalidationPlan
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 InvalidationPlan
impl Debug for InvalidationPlan
Source§impl Default for InvalidationPlan
impl Default for InvalidationPlan
Source§fn default() -> InvalidationPlan
fn default() -> InvalidationPlan
impl Eq for InvalidationPlan
Source§impl PartialEq for InvalidationPlan
impl PartialEq for InvalidationPlan
Source§fn eq(&self, other: &InvalidationPlan) -> bool
fn eq(&self, other: &InvalidationPlan) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for InvalidationPlan
Auto Trait Implementations§
impl Freeze for InvalidationPlan
impl RefUnwindSafe for InvalidationPlan
impl Send for InvalidationPlan
impl Sync for InvalidationPlan
impl Unpin for InvalidationPlan
impl UnsafeUnpin for InvalidationPlan
impl UnwindSafe for InvalidationPlan
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,
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