Skip to content

Commit 288ac25

Browse files
committed
conditional pylibmc import
1 parent dd20c01 commit 288ac25

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cache_helper/decorators.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from _pylibmc import Error as MemcachedError
1+
try:
2+
from _pylibmc import Error as CacheSetError
3+
except ImportError:
4+
from cache_helper.exceptions import CacheHelperException as CacheSetError
25

36
from django.core.cache import cache
47
from django.utils.functional import wraps
@@ -25,10 +28,11 @@ def wrapper(*args, **kwargs):
2528
if value is None:
2629
value = func(*args, **kwargs)
2730
# Try and set the key, value pair in the cache.
28-
# But if it fails on a Memcached Error handle it.
31+
# But if it fails on an error from the underlying
32+
# cache system, handle it.
2933
try:
3034
cache.set(key, value, timeout)
31-
except MemcachedError:
35+
except CacheSetError:
3236
pass
3337

3438
return value

0 commit comments

Comments
 (0)