Leaflet outside of pipeline b/c of paths.
[wolnelektury.git] / src / wolnelektury / signals.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django.conf import settings
5 from django.core.cache import caches
6 from django.db.models.signals import post_save, post_delete
7 from django.dispatch import receiver
8
9 from funding.models import Spent
10 from infopages.models import InfoPage
11 from libraries.models import Catalog, Library
12 from pdcounter.models import Author, BookStub
13
14
15 @receiver([post_save, post_delete])
16 def flush_views_after_manual_change(sender, **kwargs):
17     """Flushes views cache after changes with some models.
18
19     Changes to those models happen infrequently, so we can afford
20     to just flush the cache on those instances.
21
22     If changes become too often, relevant bits should be separated
23     and cached and flushed individually when needed.
24
25     """
26     if sender in (Catalog, Library, InfoPage, Author, BookStub, Spent):
27         caches[settings.CACHE_MIDDLEWARE_ALIAS].clear()