From a7af5268de0bebc5d9d7a70c84dd32dd20adc791 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 21 Mar 2019 16:27:37 +0100 Subject: [PATCH] Invalidate cache when ApplicationGateway instance is saved --- passbook/app_gw/apps.py | 5 +++++ passbook/app_gw/signals.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 passbook/app_gw/signals.py diff --git a/passbook/app_gw/apps.py b/passbook/app_gw/apps.py index 6ad71d8de..9c696ae3e 100644 --- a/passbook/app_gw/apps.py +++ b/passbook/app_gw/apps.py @@ -1,4 +1,6 @@ """passbook Application Security Gateway app""" +from importlib import import_module + from django.apps import AppConfig @@ -9,3 +11,6 @@ class PassbookApplicationApplicationGatewayConfig(AppConfig): label = 'passbook_app_gw' verbose_name = 'passbook Application Security Gateway' mountpoint = 'app_gw/' + + def ready(self): + import_module('passbook.app_gw.signals') diff --git a/passbook/app_gw/signals.py b/passbook/app_gw/signals.py new file mode 100644 index 000000000..cb07171eb --- /dev/null +++ b/passbook/app_gw/signals.py @@ -0,0 +1,20 @@ +"""passbook app_gw cache clean signals""" + +from logging import getLogger + +from django.core.cache import cache +from django.db.models.signals import post_save +from django.dispatch import receiver + +from passbook.app_gw.middleware import IGNORED_HOSTNAMES_KEY +from passbook.app_gw.models import ApplicationGatewayProvider + +LOGGER = getLogger(__name__) + +@receiver(post_save) +# pylint: disable=unused-argument +def invalidate_app_gw_cache(sender, instance, **kwargs): + """Invalidate Policy cache when app_gw is updated""" + if isinstance(instance, ApplicationGatewayProvider): + LOGGER.debug("Invalidating cache for ignored hostnames") + cache.delete(IGNORED_HOSTNAMES_KEY)