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