"""Scheduled cache maintenance.

Added after incident 2026-03-14 (see `docs/incidents/`). Cache memory grew
monotonically until the instance reached `maxmemory` and intake stopped. The
nightly purge keeps memory bounded.

Redis is a cache -- per `docs/ARCHITECTURE.md` it holds no system-of-record
data -- so this is safe to run against a live system.
"""

from __future__ import annotations

import logging

from celery import shared_task
from django.core.cache import cache

logger = logging.getLogger(__name__)


@shared_task
def purge_cache() -> None:
    """Drop everything in the shared cache.

    Runs nightly at 04:00 UTC. Anything removed is either reconstructible from
    MySQL or is in-flight broker state.
    """

    cache.clear()
    logger.info("scheduled cache purge complete")
