Skip to content

Commit

Permalink
conditional pylibmc import
Browse files Browse the repository at this point in the history
  • Loading branch information
jpo424 committed Jun 29, 2017
1 parent dd20c01 commit 288ac25
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cache_helper/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from _pylibmc import Error as MemcachedError
try:
from _pylibmc import Error as CacheSetError
except ImportError:
from cache_helper.exceptions import CacheHelperException as CacheSetError

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

return value
Expand Down

0 comments on commit 288ac25

Please sign in to comment.