fix: always enable cache

pull/14/head
Raphaël Vinot 2018-12-17 19:50:55 +01:00
parent f3ebe74042
commit 5df3add8de
1 changed files with 30 additions and 38 deletions

View File

@ -39,19 +39,17 @@ try:
except Exception:
sphinx = False
enable_cache = True
r_cache = None
def _cache_init():
global r_cache
if enable_cache and r_cache is None:
if r_cache is None:
r_cache = redis.Redis(unix_socket_path=get_socket_path('cache'), db=1, decode_responses=True)
def _cache_set(key, value, field=None):
_cache_init()
if enable_cache:
if field is None:
r_cache.setex(key, json.dumps(value), 3600)
else:
@ -61,7 +59,6 @@ def _cache_set(key, value, field=None):
def _cache_get(key, field=None):
_cache_init()
if enable_cache:
if field is None:
value_json = r_cache.get(key)
else:
@ -80,7 +77,6 @@ def to_bool(s):
def get_submissions(url, day=None):
_cache_init()
if enable_cache:
if day is None:
day = date.today().isoformat()
else:
@ -91,7 +87,6 @@ def get_submissions(url, day=None):
def get_mail_sent(url, day=None):
_cache_init()
if enable_cache:
if day is None:
day = date.today().isoformat()
else:
@ -102,7 +97,6 @@ def get_mail_sent(url, day=None):
def set_mail_sent(url, day=None):
_cache_init()
if enable_cache:
if day is None:
day = date.today().isoformat()
else:
@ -545,8 +539,6 @@ def get_url_data(url):
def cached(url):
_cache_init()
if not enable_cache:
return [url]
url_data = get_url_data(url)
to_return = [url_data]
if url_data[url].get('list') is not None: