From f5179bad71a5b5e65f70172b177abdcb3896fca2 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 23 Sep 2016 12:27:43 +0200 Subject: Cache: manage long keys - immediatly refresh cache after types modifications --- ishtar_common/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index ca9193204..60c3ac7ef 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -17,6 +17,7 @@ # See the file COPYING for details. +import hashlib import random from django.conf import settings @@ -41,6 +42,13 @@ def get_cache(cls, extra_args=[]): else: cache_key += '-' + unicode(arg) cache_key = slugify(cache_key) + if not cache_key.endswith('_current_keys') \ + and hasattr(cls, '_add_cache_key_to_refresh'): + cls._add_cache_key_to_refresh(extra_args) + if len(cache_key) >= 250: + m = hashlib.md5() + m.update(cache_key) + cache_key = m.hexdigest() return cache_key, cache.get(cache_key) -- cgit v1.2.3