Skip to content

Commit

Permalink
flush cache properly
Browse files Browse the repository at this point in the history
  • Loading branch information
toresbe committed Sep 22, 2020
1 parent 0ee3586 commit b0d5b1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions packages/fkweb/fk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion packages/fkweb/fkws/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0d5b1f

Please sign in to comment.