summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2020-08-14 22:58:16 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-20 08:58:50 +0200
commit0cb0d59b2332bd6dc1705d59ac1a9c1994fa764e (patch)
treec8f34be1a10048a86b03555545067d5dac349658
parent67e4a9a4b9a40609fecc14f1604929ff2259a15a (diff)
Fixed comments related to nonexistent keys for incr()/decr() in memcached backends.
-rw-r--r--django/core/cache/backends/memcached.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
index cd0a6984ec..4b0f8f6b8e 100644
--- a/django/core/cache/backends/memcached.py
+++ b/django/core/cache/backends/memcached.py
@@ -18,10 +18,8 @@ class BaseMemcachedCache(BaseCache):
else:
self._servers = server
- # The exception type to catch from the underlying library for a key
- # that was not found. This is a ValueError for python-memcache,
- # pylibmc.NotFound for pylibmc, and cmemcache will return None without
- # raising an exception.
+ # Exception type raised by the underlying client library for a
+ # nonexistent key.
self.LibraryValueNotFoundException = value_not_found_exception
self._lib = library
@@ -106,10 +104,8 @@ class BaseMemcachedCache(BaseCache):
try:
val = self._cache.incr(key, delta)
- # python-memcache responds to incr on nonexistent keys by
- # raising a ValueError, pylibmc by raising a pylibmc.NotFound
- # and Cmemcache returns None. In all cases,
- # we should raise a ValueError though.
+ # Normalize an exception raised by the underlying client library to
+ # ValueError in the event of a nonexistent key when calling incr().
except self.LibraryValueNotFoundException:
val = None
if val is None:
@@ -125,10 +121,8 @@ class BaseMemcachedCache(BaseCache):
try:
val = self._cache.decr(key, delta)
- # python-memcache responds to incr on nonexistent keys by
- # raising a ValueError, pylibmc by raising a pylibmc.NotFound
- # and Cmemcache returns None. In all cases,
- # we should raise a ValueError though.
+ # Normalize an exception raised by the underlying client library to
+ # ValueError in the event of a nonexistent key when calling decr().
except self.LibraryValueNotFoundException:
val = None
if val is None:
@@ -160,6 +154,8 @@ class BaseMemcachedCache(BaseCache):
class MemcachedCache(BaseMemcachedCache):
"An implementation of a cache binding using python-memcached"
def __init__(self, server, params):
+ # python-memcached ≥ 1.45 returns None for a nonexistent key in
+ # incr/decr(), python-memcached < 1.45 raises ValueError.
import memcache
super().__init__(server, params, library=memcache, value_not_found_exception=ValueError)