[Update] 修改Org刷新cache

pull/1688/head
ibuler 2018-08-13 18:26:13 +08:00
parent 75e67410cf
commit 1c5ce61ed0
3 changed files with 17 additions and 1 deletions

View File

@ -3,3 +3,6 @@ from django.apps import AppConfig
class OrgsConfig(AppConfig):
name = 'orgs'
def ready(self):
from . import signals_handler

View File

@ -27,7 +27,7 @@ class Organization(models.Model):
def expire_cache(self):
key = self.CACHE_PREFIX.format(self.id)
cache.set(key, self, 0)
cache.set(key, self, 1)
@classmethod
def get_instance_from_cache(cls, oid):

View File

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
#
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Organization
@receiver(post_save, sender=Organization)
def on_org_update(sender, instance=None, created=False, **kwargs):
if instance and not created:
instance.expire_cache()