Make sure cache.set never fails hard (#611)

This commit is contained in:
Maxime Beauchemin 2016-06-13 13:26:05 -07:00 committed by GitHub
parent 9ed8c32f76
commit 267c0191a8

View File

@ -261,7 +261,12 @@ class BaseViz(object):
payload['cached_dttm'] = datetime.now().isoformat().split('.')[0]
logging.info("Caching for the next {} seconds".format(
cache_timeout))
cache.set(cache_key, payload, timeout=cache_timeout)
try:
cache.set(cache_key, payload, timeout=cache_timeout)
except Exception as e:
# cache.set call can fail if the backend is down or if
# the key is too large or whatever other reasons
logging.warning("Could not cache key {}".format(cache_key))
payload['is_cached'] = is_cached
return self.json_dumps(payload)