summaryrefslogtreecommitdiff
path: root/django/core/cache
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2020-08-14 23:17:04 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-01 10:51:00 +0200
commitcc1f2c6a199ca2318acdc59bf0731d2cdd7a4e4a (patch)
tree0c9a4c91041effe84b16241700132d64218ae131 /django/core/cache
parent7a60670b78894cae0f5f21d39f10fa38b1283497 (diff)
Refs #29887 -- Simplified memcached client instantiation.
Diffstat (limited to 'django/core/cache')
-rw-r--r--django/core/cache/backends/memcached.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
index d331642f09..ed3f2af492 100644
--- a/django/core/cache/backends/memcached.py
+++ b/django/core/cache/backends/memcached.py
@@ -23,17 +23,15 @@ class BaseMemcachedCache(BaseCache):
self.LibraryValueNotFoundException = value_not_found_exception
self._lib = library
+ self._class = library.Client
self._options = params.get('OPTIONS') or {}
- @property
+ @cached_property
def _cache(self):
"""
Implement transparent thread-safe access to a memcached client.
"""
- if getattr(self, '_client', None) is None:
- self._client = self._lib.Client(self._servers, **self._options)
-
- return self._client
+ return self._class(self._servers, **self._options)
def get_backend_timeout(self, timeout=DEFAULT_TIMEOUT):
"""
@@ -166,14 +164,7 @@ class MemcachedCache(BaseMemcachedCache):
# incr/decr(), python-memcached < 1.45 raises ValueError.
import memcache
super().__init__(server, params, library=memcache, value_not_found_exception=ValueError)
-
- @property
- def _cache(self):
- if getattr(self, '_client', None) is None:
- client_kwargs = {'pickleProtocol': pickle.HIGHEST_PROTOCOL}
- client_kwargs.update(self._options)
- self._client = self._lib.Client(self._servers, **client_kwargs)
- return self._client
+ self._options = {'pickleProtocol': pickle.HIGHEST_PROTOCOL, **self._options}
def get(self, key, default=None, version=None):
key = self.make_key(key, version=version)
@@ -201,10 +192,6 @@ class PyLibMCCache(BaseMemcachedCache):
import pylibmc
super().__init__(server, params, library=pylibmc, value_not_found_exception=pylibmc.NotFound)
- @cached_property
- def _cache(self):
- return self._lib.Client(self._servers, **self._options)
-
def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None):
key = self.make_key(key, version=version)
self.validate_key(key)