summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-12-13 20:35:06 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-12-13 20:35:06 +0000
commit07ba0dbaf75a72c3c3ab71ca5a80f0889ddabb72 (patch)
treeee751936dabc51e796699a83b2e98a60472e7cad
parent1c5fe467bd838c8521ca7c7427d8196f08a24f80 (diff)
Fixed #10646: `cache.incr()` and `decr()` now fail consistantly under python-memcache and cmemcache.
Though it looks like this commit has no tests that's not so: this is tested for in `regressiontests/cache/tests.py` around like 183; these tests currently fail if ran against cmemcache. Thanks, andrewfong. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/cache/backends/memcached.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
index 0ff0da32ae..d5e6394f92 100644
--- a/django/core/cache/backends/memcached.py
+++ b/django/core/cache/backends/memcached.py
@@ -46,7 +46,28 @@ class CacheClass(BaseCache):
self._cache.disconnect_all()
def incr(self, key, delta=1):
- return self._cache.incr(key, delta)
+ try:
+ val = self._cache.incr(key, delta)
+
+ # python-memcache responds to incr on non-existent keys by
+ # raising a ValueError. Cmemcache returns None. In both
+ # cases, we should raise a ValueError though.
+ except ValueError:
+ val = None
+ if val is None:
+ raise ValueError("Key '%s' not found" % key)
+
+ return val
def decr(self, key, delta=1):
- return self._cache.decr(key, delta)
+ try:
+ val = self._cache.decr(key, delta)
+
+ # python-memcache responds to decr on non-existent keys by
+ # raising a ValueError. Cmemcache returns None. In both
+ # cases, we should raise a ValueError though.
+ except ValueError:
+ val = None
+ if val is None:
+ raise ValueError("Key '%s' not found" % key)
+ return val