perf: HTTP caching headers for /api/query_results [fixes #228]

This commit is contained in:
Amir Nissim 2014-08-04 16:20:44 +03:00
parent c2d621ae0f
commit a12b43265d
2 changed files with 11 additions and 1 deletions

8
redash/cache.py Normal file
View File

@ -0,0 +1,8 @@
from flask import make_response
from functools import update_wrapper
ONE_YEAR = 60 * 60 * 24 * 365.25
headers = {
'Cache-Control': 'max-age=%d' % ONE_YEAR
}

View File

@ -26,6 +26,7 @@ from redash.wsgi import app, auth, api
import logging
from tasks import QueryTask
from cache import headers as cache_headers
@app.route('/ping', methods=['GET'])
def ping():
@ -417,7 +418,8 @@ class QueryResultAPI(BaseResource):
def get(self, query_result_id):
query_result = models.QueryResult.get_by_id(query_result_id)
if query_result:
return {'query_result': query_result.to_dict()}
data = json.dumps({'query_result': query_result.to_dict()}, cls=utils.JSONEncoder)
return make_response(data, 200, cache_headers)
else:
abort(404)