Skip to content

InvalidationRule

The dataclass that connects a Django model's signals to a CachedWrapper. See the Invalidation Rules guide for an overview and worked examples.

InvalidationRule dataclass

InvalidationRule(
    model: type[Model],
    rewarm: bool = False,
    field_mapping: dict[str, str] = dict(),
    require_args: bool | list[str] = True,
    trigger_on_create: bool = False,
    watch_fields: list[str] | None = None,
    invalidate_when: dict[str, Any] = dict(),
    invalidator: Callable[..., None] | str | None = None,
    dispatcher: str | type[Dispatcher] | None = None,
    dispatcher_config: dict[str, Any] = dict(),
    batch: bool = False,
    raise_exception: bool | None = None,
)

Declarative rule that connects a Django model's signals to cache invalidation.

A rule invalidates in one of two ways: a field_mapping that maps cache-key argument names onto attributes of the saving instance, or a custom invalidator callable that takes over the work.

resolve_invalidator

resolve_invalidator() -> Callable[..., None]

Return the invalidator as a callable, importing dotted-path strings on first use.

get_dispatcher

get_dispatcher() -> Dispatcher

Return the Dispatcher instance for this rule, building it on the first call and caching it.