mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 08:31:00 -04:00
Change code order for Redis delete decorator
Before, the delete decorator would delete the keys from Redis and then we made the request to api to change the data. However, it is possible that the cache could get re-populated in between these two things happening, and so would cache outdated data. This changes the order to send the api request first. We then always delete the specified keys from Redis. Changing the order of the code in the decorator changes the order in which the cache keys get deleted, so the tests have been updated.
This commit is contained in:
@@ -61,9 +61,12 @@ def delete(key_format):
|
||||
|
||||
@wraps(client_method)
|
||||
def new_client_method(client_instance, *args, **kwargs):
|
||||
redis_key = _make_key(key_format, client_method, args, kwargs)
|
||||
redis_client.delete(redis_key)
|
||||
return client_method(client_instance, *args, **kwargs)
|
||||
try:
|
||||
api_response = client_method(client_instance, *args, **kwargs)
|
||||
finally:
|
||||
redis_key = _make_key(key_format, client_method, args, kwargs)
|
||||
redis_client.delete(redis_key)
|
||||
return api_response
|
||||
|
||||
return new_client_method
|
||||
|
||||
|
||||
Reference in New Issue
Block a user