pub fn register_invalidator_on<E, F>(
dispatcher: &EventDispatcher,
cache: Arc<Cache>,
key_fn: F,
)Expand description
Register a cache-invalidation listener on an arbitrary
EventDispatcher.
When an event of type E is dispatched through dispatcher, key_fn
is invoked with the event to compute the set of tags to flush. Each
tag is flushed via Cache::tags + crate::TaggedCache::flush;
per-tag flush failures are tracing::warn!’d and swallowed at the
dispatcher boundary so a degraded cache cannot brick the write path
that fired the event.
Multiple invalidators may be registered for the same event type on the same dispatcher — all run; order between them is unspecified.
Prefer register_invalidator for the common case of registering on
the process-wide global_dispatcher. Use this overload when the
consumer holds a non-global dispatcher (isolated per-tenant context,
per-test fixture, embedded library inside a larger app, …).
§Parameters
dispatcher: the dispatcher to register the listener on.cache: anArc<Cache>whose store backs the tag flushing.key_fn: a closureFn(&E) -> Vec<String>returning the tags to flush. Returning an emptyVecis a no-op (and skips the per-tag flush calls).