diff --git a/caravel/config.py b/caravel/config.py index 18c9d5c69f064..134127f37d5d2 100644 --- a/caravel/config.py +++ b/caravel/config.py @@ -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') + diff --git a/caravel/viz.py b/caravel/viz.py index 36db12a7ee73f..5c0c6df174261 100644 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -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") @@ -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, @@ -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)