diff --git a/django_elasticache/__init__.py b/django_elasticache/__init__.py index 81598db..65f9591 100644 --- a/django_elasticache/__init__.py +++ b/django_elasticache/__init__.py @@ -1,2 +1,2 @@ -VERSION = (1, 0, 3) +VERSION = (1, 0, 4) __version__ = '.'.join(map(str, VERSION)) diff --git a/django_elasticache/memcached.py b/django_elasticache/memcached.py index a78fbd7..0b0caf3 100644 --- a/django_elasticache/memcached.py +++ b/django_elasticache/memcached.py @@ -2,12 +2,17 @@ Backend for django cache """ import socket +import logging + from functools import wraps from django.core.cache import InvalidCacheBackendError from django.core.cache.backends.memcached import PyLibMCCache from .cluster_utils import get_cluster_info +log = logging.getLogger('django.elasticache') + + def invalidate_cache_after_error(f): """ catch any exception and invalidate internal cache with list of nodes @@ -16,9 +21,10 @@ def invalidate_cache_after_error(f): def wrapper(self, *args, **kwds): try: return f(self, *args, **kwds) - except Exception: + except Exception as e: + log.warning('MemcachedError: %s', e, exc_info=True) self.clear_cluster_nodes_cache() - raise + return None # Treat as a cache miss return wrapper @@ -103,6 +109,10 @@ def _cache(self): return client + @invalidate_cache_after_error + def add(self, *args, **kwargs): + return super(ElastiCache, self).add(*args, **kwargs) + @invalidate_cache_after_error def get(self, *args, **kwargs): return super(ElastiCache, self).get(*args, **kwargs) @@ -122,3 +132,7 @@ def set_many(self, *args, **kwargs): @invalidate_cache_after_error def delete(self, *args, **kwargs): return super(ElastiCache, self).delete(*args, **kwargs) + + @invalidate_cache_after_error + def delete_many(self, *args, **kwargs): + return super(ElastiCache, self).delete_many(*args, **kwargs)