Skip to content

Commit

Permalink
[hotfix] adding cache_key in payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 25, 2016
1 parent 7d90f26 commit 37be01b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions caravel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@
from caravel_config import * # noqa
except Exception:
pass

if not CACHE_DEFAULT_TIMEOUT:
CACHE_DEFAULT_TIMEOUT = CACHE_CONFIG.get('CACHE_DEFAULT_TIMEOUT')

9 changes: 6 additions & 3 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,14 @@ def query_obj(self):

@property
def cache_timeout(self):

if self.slice and self.slice.cache_timeout:
return self.slice.cache_timeout
if self.datasource.cache_timeout:
return self.datasource.cache_timeout
if hasattr(self.datasource, 'database') \
and self.datasource.database.cache_timeout:
if (
hasattr(self.datasource, 'database') and
self.datasource.database.cache_timeout):
return self.datasource.database.cache_timeout
return config.get("CACHE_DEFAULT_TIMEOUT")

Expand All @@ -247,6 +249,7 @@ def get_json(self):
cache_timeout = self.cache_timeout
payload = {
'cache_timeout': cache_timeout,
'cache_key': cache_key,
'csv_endpoint': self.csv_endpoint,
'data': self.get_data(),
'form_data': self.form_data,
Expand All @@ -257,7 +260,7 @@ def get_json(self):
payload['cached_dttm'] = datetime.now().isoformat().split('.')[0]
logging.info("Caching for the next {} seconds".format(
cache_timeout))
cache.set(cache_key, payload, timeout=self.cache_timeout)
cache.set(cache_key, payload, timeout=cache_timeout)
payload['is_cached'] = is_cached
return self.json_dumps(payload)

Expand Down

0 comments on commit 37be01b

Please sign in to comment.