Skip to content

Dispatchers

The dispatcher layer routes invalidation work to the right runtime. See the Dispatchers guide for an overview and per-broker setup.

Dispatcher

Dispatcher(**config: Any)

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

dispatch(
    *,
    rule_ids: list[int],
    rule_kwargs: dict[str, dict[str, Any]],
    **context: Any,
) -> None

Run one group of invalidation rules.

validate_config

validate_config() -> None

Hook for subclasses to validate config or import optional dependencies, no-op by default.

batch_key

batch_key() -> tuple

Return a hashable identity that groups rules into a single dispatch call.

settings classmethod

settings() -> dict[str, Any]

Return the merged settings block for this dispatcher.

InlineDispatcher

InlineDispatcher(**config: Any)

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

ThreadPoolDispatcher(**config: Any)

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.

validate_config

validate_config() -> None

Verify max_workers is a positive integer when supplied.

dispatch

dispatch(
    *,
    rule_ids: list[int],
    rule_kwargs: dict[str, dict[str, Any]],
    **_context: Any,
) -> None

Submit the rules to the shared thread-pool executor.

AsyncIODispatcher

AsyncIODispatcher(**config: Any)

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

CeleryDispatcher(**config: Any)

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.

validate_config

validate_config() -> None

Verify Celery is installed and importable.

batch_key

batch_key() -> tuple

Group rules by Celery task name and queue.

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

DjangoRqDispatcher(**config: Any)

Bases: Dispatcher

Hand invalidation work off to django-rq.

validate_config

validate_config() -> None

Verify django-rq is installed and importable.

batch_key

batch_key() -> tuple

Group rules by RQ queue and worker function path.

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

DjangoQDispatcher(**config: Any)

Bases: Dispatcher

Hand invalidation work off to django-q or django-q2.

validate_config

validate_config() -> None

Verify django-q is installed and importable.

batch_key

batch_key() -> tuple

Group rules by cluster, group, and worker function path.

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

DramatiqDispatcher(**config: Any)

Bases: Dispatcher

Hand invalidation work off to a Dramatiq actor.

validate_config

validate_config() -> None

Verify Dramatiq is installed and importable.

batch_key

batch_key() -> tuple

Group rules by Dramatiq queue and actor name.

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.

register_dispatcher module-attribute

register_dispatcher = register

registered_dispatcher_names module-attribute

registered_dispatcher_names = registered_names