From 07788d1de9b928b84e7e7ab040c9acdfd1ea80f4 Mon Sep 17 00:00:00 2001 From: xenua Date: Sun, 19 Jun 2022 17:34:10 +0200 Subject: [PATCH] implement cache invalidation --- leftists/apps.py | 7 +++++++ leftists/signals.py | 4 ++++ 2 files changed, 11 insertions(+) create mode 100644 leftists/signals.py diff --git a/leftists/apps.py b/leftists/apps.py index 7f1e36e..a17361a 100644 --- a/leftists/apps.py +++ b/leftists/apps.py @@ -1,6 +1,13 @@ from django.apps import AppConfig +from django.db.models.signals import pre_save class LeftistsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'leftists' + + def ready(self): + from . import signals + from .models import ShortLink + + pre_save.connect(signals.rmcache, sender=ShortLink) diff --git a/leftists/signals.py b/leftists/signals.py new file mode 100644 index 0000000..766a30b --- /dev/null +++ b/leftists/signals.py @@ -0,0 +1,4 @@ +def rmcache(sender, **kwargs): + inst = kwargs.get("instance") + if inst.domain.fqdn in sender.cache: + del sender.cache[inst.domain.fqdn][inst.location]