From 7fc5b91f6d4e22ba1384d31082d751ddf48504f2 Mon Sep 17 00:00:00 2001 From: Alex Ball Date: Mon, 5 Oct 2020 11:40:12 -0400 Subject: [PATCH] Handle failures in cache.add(), cache.set_multi() --- django_ft_cache.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/django_ft_cache.py b/django_ft_cache.py index 076d396..12dfbba 100644 --- a/django_ft_cache.py +++ b/django_ft_cache.py @@ -15,7 +15,11 @@ def wrapper(*args, **kwargs): except Exception as err: logger.error(u"cache.%s failed with args: %s", f.__name__, args) logger.exception(err) - result = None + if f.__name__ == 'set_multi': + # set_multi() returns a list of failed keys. Pretend that none have failed. + result = [] + else: + result = None return result return wrapper @@ -25,7 +29,7 @@ class FaultTolerantCacheMixin(object): Wraps memcache client methods allowing them to fail without raising an exception. """ - methods_to_patch = ('get', 'set', 'incr', 'decr', 'delete', + methods_to_patch = ('add', 'get', 'set', 'incr', 'decr', 'delete', 'get_multi', 'set_multi', 'delete_multi') @cached_property