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.
This commit is contained in:
parent
e2559fab30
commit
4deb681b99
13
app.py
13
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user