Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
[#72069960] Add in cache control switch in query responses
Browse files Browse the repository at this point in the history
- `fetch` Could possibly do with being refactored so that we use our cache_control class methods to serve the fetch response at all times, rather than playing around with the response headers in the method. Probably alright for the context of [this story](https://www.pivotaltracker.com/story/show/72069960) though
  • Loading branch information
Ralph Cowling committed Jun 4, 2014
1 parent 6dc825e commit 7ff610c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions backdrop/read/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,20 @@ def fetch(data_set_config):
warning = ("Warning: This data-set is unpublished. "
"Data may be subject to change or be inaccurate.")
response = jsonify(data=data, warning=warning)
# Do not cache unpublished data-sets
response.headers['Cache-Control'] = "no-cache, must-revalidate"
else:
response = jsonify(data=data)
# Set cache control based on data-set max_age
response.headers['Cache-Control'] = (
"max-age=%d, "
"must-revalidate" % data_set_config.max_age
)

# Headers
# allow requests from any origin
response.headers['Access-Control-Allow-Origin'] = '*'

response.headers['Cache-Control'] = "max-age=%d, must-revalidate" % \
data_set_config.max_age

return response


Expand Down

0 comments on commit 7ff610c

Please sign in to comment.