Commit 9ff68794 authored by Tomi Suomela's avatar Tomi Suomela

try_delete() added

parent 4e30884a
......@@ -284,8 +284,8 @@ class BaseRedisCache(BaseCache):
@get_client(write=True)
def delete(self, client, key):
"""Remove a key from the cache."""
client.delete("__fresh__" + key)
return client.delete(key)
all_keys = ["__fresh__" + key, key]
return client.delete(*all_keys)
def _delete_many(self, client, keys):
all_keys = keys.copy()
......@@ -505,3 +505,19 @@ class BaseRedisCache(BaseCache):
Returns True if successful and False if not.
"""
return client.persist(key)
@get_client(write=True)
def try_delete(self, client, key):
"""Remove a key from the cache if not locked."""
lock = cache.lock(key, timeout=5)
acquired = lock.acquire(blocking=False)
if acquired:
try:
all_keys = ["__fresh__" + key, key]
client.delete(*all_keys)
except Exception:
raise
finally:
lock.release()
return acquired
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment