Skip to content
Snippets Groups Projects

Invalidate both database backends

Merged Nik | Klampfradler requested to merge default-oot-cachalot into master
2 files
+ 22
0
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -17,6 +17,8 @@ from django.utils.crypto import get_random_string
from django.utils.functional import lazy
from django.utils.module_loading import import_string
from cachalot.api import invalidate
from cachalot.signals import post_invalidation
from cache_memoize import cache_memoize
@@ -403,6 +405,8 @@ class OOTRouter:
default_db = "default"
oot_db = "default_oot"
_cachalot_invalidating = []
@property
def oot_labels(self):
return settings.DATABASE_OOT_LABELS
@@ -441,3 +445,20 @@ class OOTRouter:
return False
return None
@classmethod
def _invalidate_cachalot(cls, sender, **kwargs):
if sender in cls._cachalot_invalidating:
return
cls._cachalot_invalidating.append(sender)
if kwargs["db_alias"] == cls.default_db:
invalidate(sender, db_alias=cls.oot_db)
elif kwargs["db_alias"] == cls.oot_db:
invalidate(sender, db_alias=cls.default_db)
cls._cachalot_invalidating.remove(sender)
post_invalidation.connect(OOTRouter._invalidate_cachalot)
Loading