Commit ae8bc6aa authored by Lukas Burgey's avatar Lukas Burgey

Fix cache flushing

parent 021c627d
......@@ -4,7 +4,7 @@ import hashlib
# api cache
CACHING = True
CACHE = caches['default']
CACHE_VALID = False
CACHE_NAMES = []
def get_cache_name(module, func, *args, **kwargs):
m = hashlib.md5()
......@@ -19,22 +19,21 @@ def get_cache_name(module, func, *args, **kwargs):
return cache_name
def get_cached(module, func, *args, **kwargs):
global CACHE_VALID
if not CACHING:
return getattr(module, func)(*args, **kwargs)
cache_name = get_cache_name(module, func, *args, **kwargs)
content = CACHE.get(cache_name)
if (
CACHE_VALID and not content == None
):
if not content == None:
return content
content = getattr(module, func)(*args, **kwargs)
CACHE_NAMES.append(cache_name)
CACHE.set(cache_name, content, None)
CACHE_VALID = True
return content
def invalidate_caches():
CACHE_VALID = False
global CACHE_NAMES
for name in CACHE_NAMES:
CACHE.delete(name)
CACHE_NAMES = []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment