From b0d5b1fae45ccec236dfbd1dbfc8d7bd620ffa43 Mon Sep 17 00:00:00 2001 From: Tore Sinding Bekkedal Date: Tue, 22 Sep 2020 21:29:09 +0200 Subject: [PATCH] flush cache properly --- packages/fkweb/fk/models.py | 14 +++++++++----- packages/fkweb/fkws/views.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/fkweb/fk/models.py b/packages/fkweb/fk/models.py index 39e63872..40c0d6ad 100644 --- a/packages/fkweb/fk/models.py +++ b/packages/fkweb/fk/models.py @@ -4,15 +4,19 @@ import os import uuid +import logging +logger = logging.getLogger(__name__) + import pytz from django.conf import settings from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.contrib.auth import get_user_model from django.core.cache import caches from django.core.exceptions import ObjectDoesNotExist +from django.dispatch import receiver from django.urls import reverse from django.db import models -from django.db.models.signals import post_save +from django.db.models.signals import post_save, post_delete from django.utils import timezone from django.utils.timezone import utc from django.utils.translation import ugettext as _ @@ -461,12 +465,12 @@ class Meta: verbose_name_plural = 'TX schedule entries' ordering = ('-id',) - def _clear_cache(self): + @staticmethod + @receiver([post_save, post_delete]) + def _clear_cache(**kwargs): + logger.warning('[Scheduleitem] cache flush') caches['schedule'].clear() - post_save = _clear_cache - post_delete = _clear_cache - def __str__(self): t = self.starttime s = t.strftime("%Y-%m-%d %H:%M:%S") diff --git a/packages/fkweb/fkws/views.py b/packages/fkweb/fkws/views.py index 5caddf20..36ee0084 100644 --- a/packages/fkweb/fkws/views.py +++ b/packages/fkweb/fkws/views.py @@ -214,7 +214,7 @@ def dispatch(self, request, *args, **kwargs): cache = caches['schedule'] cache_key = 'schedule-%s-%s' % (date.strftime('%Y%m%d'), days) - if request.headers.get('Accept', '') != '*/*': cacheable: False + if request.headers.get('Accept', '') != '*/*': cacheable = False if params.get('surrounding') != None: cacheable = False if params.get('ordering') != None: cacheable = False if params.get('page_size') != None: cacheable = False