From 412d0bf9d02e2ba6a54db2838b40c473b11b384d Mon Sep 17 00:00:00 2001 From: Hannah Pho Date: Mon, 5 Aug 2024 15:30:54 -0400 Subject: [PATCH] Update cache key for stat var search POSTs (#4537) Quick fix to follow up https://github.com/datacommonsorg/website/pull/4534 and unblock the website release. For the future it would be nice to wrap @cache.cached in a custom decorator that we can use everywhere which takes care of passing default params and making sure post body is in the cache key. --- server/routes/shared_api/stats.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/routes/shared_api/stats.py b/server/routes/shared_api/stats.py index ea429c725d..8e3c7022b1 100644 --- a/server/routes/shared_api/stats.py +++ b/server/routes/shared_api/stats.py @@ -22,6 +22,7 @@ from server.lib import fetch from server.lib import shared from server.lib.cache import cache +import server.lib.util as lib_util from server.routes import TIMEOUT import server.services.datacommons as dc @@ -99,7 +100,9 @@ def stat_var_property(): @bp.route('/stat-var-search', methods=('GET', 'POST')) -@cache.cached(timeout=TIMEOUT, query_string=True) +@cache.cached(timeout=TIMEOUT, + query_string=True, + make_cache_key=lib_util.post_body_cache_key) def search_statvar(): """Gets the statvars and statvar groups that match the tokens in the query.""" if request.method == 'GET':