[odrs-web] odrs: Add caching support to fetch and ratings endpoints
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [odrs-web] odrs: Add caching support to fetch and ratings endpoints
- Date: Wed, 16 Mar 2022 16:31:18 +0000 (UTC)
commit f077fe5b2e269ed4950513bd7b44df61146237f9
Author: Philip Withnall <withnall endlessm com>
Date: Tue Aug 11 16:04:21 2020 +0100
odrs: Add caching support to fetch and ratings endpoints
Particularly with the ratings endpoint, this will allow users to avoid
re-downloading all the ratings data if their local cache is up to date.
Note that in production, this is already handled by the WSGI proxy
layer. It helps to be explicit in the code about what caching is
suitable for each endpoint, though.
Signed-off-by: Philip Withnall <withnall endlessm com>
app_data/odrs/views_api.py | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/app_data/odrs/views_api.py b/app_data/odrs/views_api.py
index 002e284..9527901 100644
--- a/app_data/odrs/views_api.py
+++ b/app_data/odrs/views_api.py
@@ -292,9 +292,12 @@ def api_fetch():
items_new = items_new[start : start+limit]
dat = json.dumps(items_new, sort_keys=True, indent=4, separators=(',', ': '))
- return Response(response=dat,
- status=200, \
- mimetype='application/json')
+ response = Response(response=dat,
+ status=200, \
+ mimetype='application/json')
+ response.cache_control = 'private'
+ response.add_etag()
+ return response.make_conditional(request)
@app.route('/1.0/reviews/api/moderate/<user_hash>')
@app.route('/1.0/reviews/api/moderate/<user_hash>/<locale>')
@@ -518,6 +521,9 @@ def api_ratings():
item[component.app_id] = ratings
dat = json.dumps(item, sort_keys=True, indent=4, separators=(',', ': '))
- return Response(response=dat,
- status=200, \
- mimetype='application/json')
+ response = Response(response=dat,
+ status=200, \
+ mimetype='application/json')
+ response.cache_control.public = True
+ response.add_etag()
+ return response.make_conditional(request)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]