From 608c57f71977001f8d1bc208ba0288cbf5d7fb52 Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 6 Apr 2026 17:24:55 +0100 Subject: [PATCH] fix(cache): implement query-string-based cache busting Update the `make_cache_key` function to include the request query string in the generated key. This allows for manual cache busting by appending version parameters to redirects. In the `delete_account` route, replace manual cache deletion logic with a redirect containing a timestamped nonce. This ensures that the user's account list and home page views are refreshed without requiring explicit knowledge of all internal cache keys. --- app.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 0b7e051..03730e3 100644 --- a/app.py +++ b/app.py @@ -74,6 +74,9 @@ def make_cache_key(*args, **kwargs): """Generate a cache key based on the user's session and request path.""" username = session.get('username', 'anonymous') path = request.path + # Include query string in cache key to bust cache with version parameter + if request.query_string: + return f"view/{username}/{path}?{request.query_string.decode()}" return f"view/{username}/{path}" @app.before_request @@ -298,18 +301,13 @@ def delete_account() -> Response: account_id = request.form.get("id") base_url = app.config["BACKEND_URL"] delete_user_account(base_url, session["auth_credentials"], account_id) - # Clear cache for user accounts route - cache_key = f"view/{session['username']}/accounts" - cache.delete(cache_key) - # Also clear memoized version for good measure - cache.delete_memoized(user_accounts, key_prefix=make_cache_key) - # Clear home page cache as well since it shows account stats - cache_key_home = f"view/{session['username']}/home" - cache.delete(cache_key_home) # Run the NPM config update in a background thread to remove the deleted account's redirect thread = threading.Thread(target=_update_npm_config_in_background, args=(session["auth_credentials"],)) thread.start() - return redirect(url_for("user_accounts")) + # Redirect with a version nonce to bust all caches + import time + nonce = int(time.time()) + return redirect(f"{url_for('user_accounts')}?_v={nonce}") @app.route("/validateAccount", methods=["POST"]) def validate_account() -> Tuple[Response, int]: