pub struct ThingsCacheInvalidationHandler { /* private fields */ }Expand description
Bridge handler that routes InvalidationEvents into a [ThingsCache]’s
dependency-aware invalidation methods.
Register one of these on a CacheInvalidationMiddleware to make
process_event(...) actually evict cached entries:
ⓘ
let cache = Arc::new(ThingsCache::new_default());
let handler = ThingsCacheInvalidationHandler::new(Arc::clone(&cache));
middleware.register_handler(Box::new(handler));Spawns the actual eviction onto the current Tokio runtime so the
synchronous trait method can return immediately. Callers that need to
observe the post-invalidation state (e.g. tests) should yield once with
tokio::task::yield_now().await after process_event returns.
Implementations§
Source§impl ThingsCacheInvalidationHandler
impl ThingsCacheInvalidationHandler
Sourcepub fn new(cache: Arc<ThingsCache>) -> Self
pub fn new(cache: Arc<ThingsCache>) -> Self
Construct a handler with the default cache type label "things_cache".
Sourcepub fn with_cache_type(cache: Arc<ThingsCache>, cache_type: String) -> Self
pub fn with_cache_type(cache: Arc<ThingsCache>, cache_type: String) -> Self
Construct a handler with a caller-supplied cache type label.
Trait Implementations§
Source§impl CacheInvalidationHandler for ThingsCacheInvalidationHandler
impl CacheInvalidationHandler for ThingsCacheInvalidationHandler
Source§fn invalidate(&self, event: &InvalidationEvent) -> Result<()>
fn invalidate(&self, event: &InvalidationEvent) -> Result<()>
Handle cache invalidation Read more
Source§fn cache_type(&self) -> &str
fn cache_type(&self) -> &str
Get cache type name
Source§fn can_handle(&self, _event: &InvalidationEvent) -> bool
fn can_handle(&self, _event: &InvalidationEvent) -> bool
Check if this handler can handle the event
Auto Trait Implementations§
impl Freeze for ThingsCacheInvalidationHandler
impl !RefUnwindSafe for ThingsCacheInvalidationHandler
impl Send for ThingsCacheInvalidationHandler
impl Sync for ThingsCacheInvalidationHandler
impl Unpin for ThingsCacheInvalidationHandler
impl UnsafeUnpin for ThingsCacheInvalidationHandler
impl !UnwindSafe for ThingsCacheInvalidationHandler
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: 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>
Converts
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>
Converts
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