Dispatchers¶
The dispatcher layer routes invalidation work to the right runtime. See the Dispatchers guide for an overview and per-broker setup.
Dispatcher ¶
Bases: ABC
Abstract base for cache invalidation backends.
A Dispatcher decides where the invalidation work runs: synchronously
on the request thread, on a thread pool, on an asyncio event loop,
or handed off to a task broker. Subclasses set a stable name and
implement dispatch.
dispatch
abstractmethod
¶
Run one group of invalidation rules.
validate_config ¶
Hook for subclasses to validate config or import optional dependencies, no-op by default.
batch_key ¶
Return a hashable identity that groups rules into a single dispatch call.
settings
classmethod
¶
Return the merged settings block for this dispatcher.
InlineDispatcher ¶
Bases: Dispatcher
Run invalidation work synchronously on the same thread as the model save.
The default dispatcher when no dispatcher is specified on a rule.
dispatch ¶
dispatch(
*,
rule_ids: list[int],
rule_kwargs: dict[str, dict[str, Any]],
**_context: Any,
) -> None
Run the rules immediately on the calling thread.
ThreadPoolDispatcher ¶
Bases: Dispatcher
Run invalidation off the request thread on a shared ThreadPoolExecutor.
The executor is built once per process. There is no durability, work that has not finished is lost if the process exits.
AsyncIODispatcher ¶
Bases: Dispatcher
Schedule invalidation on the running asyncio event loop.
Falls back to the synchronous worker when no loop is running on the calling thread.
dispatch ¶
dispatch(
*,
rule_ids: list[int],
rule_kwargs: dict[str, dict[str, Any]],
**_context: Any,
) -> None
Schedule the rules on the running loop, or run them inline if no loop is active.
CeleryDispatcher ¶
Bases: Dispatcher
Hand invalidation work off to a Celery task.
Calls apply_async when the configured task is registered on the
current Celery app, falls back to send_task for tasks defined
only on a remote worker.
dispatch ¶
dispatch(
*,
model_label: str,
pk: Any,
rule_ids: list[int],
signal_type,
rule_kwargs: dict[str, dict[str, Any]],
) -> None
Send the rules to the configured Celery task.
DjangoRqDispatcher ¶
Bases: Dispatcher
Hand invalidation work off to django-rq.
dispatch ¶
dispatch(
*,
rule_ids: list[int],
rule_kwargs: dict[str, dict[str, Any]],
**_context: Any,
) -> None
Enqueue the rules on the resolved RQ queue.
DjangoQDispatcher ¶
Bases: Dispatcher
Hand invalidation work off to django-q or django-q2.
dispatch ¶
dispatch(
*,
rule_ids: list[int],
rule_kwargs: dict[str, dict[str, Any]],
**_context: Any,
) -> None
Enqueue the rules through django-q's async_task.
DramatiqDispatcher ¶
Bases: Dispatcher
Hand invalidation work off to a Dramatiq actor.
dispatch ¶
dispatch(
*,
rule_ids: list[int],
rule_kwargs: dict[str, dict[str, Any]],
**_context: Any,
) -> None
Send the rules to the Dramatiq actor on the resolved queue.