Invalidate cache when ApplicationGateway instance is saved

This commit is contained in:
Jens Langhammer 2019-03-21 16:27:37 +01:00
parent 6d916029bb
commit a7af5268de
2 changed files with 25 additions and 0 deletions

View File

@ -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')

View File

@ -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)