From 4deb681b993a217c429df3a52e57a134d7bf7335 Mon Sep 17 00:00:00 2001 From: Karl Date: Mon, 18 Aug 2025 14:17:24 +0100 Subject: [PATCH] fix(cache): clear additional caches in account-related routes When updating, adding, or deleting accounts, multiple cache entries need to be invalidated to ensure data consistency. This includes clearing both memoized and regular cache entries for user accounts and the home page, which displays account statistics. The changes ensure that cached data is properly refreshed across all relevant views. --- app.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app.py b/app.py index fd7d858..c9c1e66 100644 --- a/app.py +++ b/app.py @@ -266,6 +266,11 @@ def add_account() -> Union[Response, str]: # 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 thread = threading.Thread(target=_update_npm_config_in_background) thread.start() @@ -286,6 +291,11 @@ def delete_account() -> Response: # 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) return redirect(url_for("user_accounts")) @app.route("/validateAccount", methods=["POST"]) @@ -306,6 +316,9 @@ def validate_account() -> Tuple[Response, int]: response_data = response.json() if response_data.get("message") == "Account is valid and updated": cache.delete_memoized(user_accounts, key_prefix=make_cache_key) + # Also clear regular cache for good measure + cache_key = f"view/{session['username']}/accounts" + cache.delete(cache_key) # Run the NPM config update in a background thread thread = threading.Thread(target=_update_npm_config_in_background) thread.start()