bc9e7e8b93
* build(deps): bump structlog from 20.1.0 to 20.2.0 Bumps [structlog](https://github.com/hynek/structlog) from 20.1.0 to 20.2.0. - [Release notes](https://github.com/hynek/structlog/releases) - [Changelog](https://github.com/hynek/structlog/blob/master/CHANGELOG.rst) - [Commits](https://github.com/hynek/structlog/compare/20.1.0...20.2.0) Signed-off-by: dependabot[bot] <support@github.com> * *: use structlog.stdlib instead of structlog for type-hints Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jens Langhammer <jens.langhammer@beryju.org>
26 lines
876 B
Python
26 lines
876 B
Python
"""authentik policy signals"""
|
|
from django.core.cache import cache
|
|
from django.db.models.signals import post_save
|
|
from django.dispatch import receiver
|
|
from structlog.stdlib import get_logger
|
|
|
|
LOGGER = get_logger()
|
|
|
|
|
|
@receiver(post_save)
|
|
# pylint: disable=unused-argument
|
|
def invalidate_policy_cache(sender, instance, **_):
|
|
"""Invalidate Policy cache when policy is updated"""
|
|
from authentik.policies.models import Policy, PolicyBinding
|
|
|
|
if isinstance(instance, Policy):
|
|
total = 0
|
|
for binding in PolicyBinding.objects.filter(policy=instance):
|
|
prefix = (
|
|
f"policy_{binding.policy_binding_uuid.hex}_{binding.policy.pk.hex}*"
|
|
)
|
|
keys = cache.keys(prefix)
|
|
total += len(keys)
|
|
cache.delete_many(keys)
|
|
LOGGER.debug("Invalidating policy cache", policy=instance, keys=total)
|