def get_json(self): """Handles caching around the json payload retrieval""" cache_key = self.cache_key payload = None if self.form_data.get('force') != 'true': payload = cache.get(cache_key) if payload: is_cached = True logging.info("Serving from cache") else: is_cached = False cache_timeout = self.cache_timeout payload = { 'data': self.get_data(), 'query': self.query, 'form_data': self.form_data, 'json_endpoint': self.json_endpoint, 'csv_endpoint': self.csv_endpoint, 'standalone_endpoint': self.standalone_endpoint, 'cache_timeout': cache_timeout, } 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) payload['is_cached'] = is_cached return dumps(payload)
def get_json(self): """Handles caching around the json payload retrieval""" cache_key = self.cache_key payload = None if self.form_data.get('force') != 'true': payload = cache.get(cache_key) if payload: is_cached = True logging.info("Serving from cache") else: is_cached = False 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, 'json_endpoint': self.json_endpoint, 'query': self.query, 'standalone_endpoint': self.standalone_endpoint, } 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) payload['is_cached'] = is_cached return self.json_dumps(payload)