Skip to content

Commit ee47351

Browse files
committed
Updated cache.set() calls to not fail on Memcached error.
1 parent 55311b8 commit ee47351

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
!.gitignore
55
*.swp
66
*.egg*
7-
*.un~
7+
*.un~
8+
.idea

cache_helper/decorators.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from _pylibmc import Error as MemcachedError
2+
13
from django.core.cache import cache
24
from django.utils.functional import wraps
35
from cache_helper import utils
@@ -14,14 +16,20 @@ def _cached(func, *args):
1416
def wrapper(*args, **kwargs):
1517
name = utils._func_info(func, args)
1618
key = get_key(name, func_type, args, kwargs)
19+
1720
try:
1821
value = cache.get(key)
1922
except Exception:
2023
value = None
2124

2225
if value is None:
2326
value = func(*args, **kwargs)
24-
cache.set(key, value, timeout)
27+
# Try and set the key, value pair in the cache.
28+
# But if it fails on a Memcached Error handle it.
29+
try:
30+
cache.set(key, value, timeout)
31+
except MemcachedError:
32+
pass
2533

2634
return value
2735

@@ -31,4 +39,4 @@ def invalidate(*args, **kwargs):
3139
cache.delete(key)
3240
wrapper.invalidate = invalidate
3341
return wrapper
34-
return _cached
42+
return _cached

0 commit comments

Comments
 (0)