summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2020-08-15 21:34:32 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-02 08:51:17 +0200
commita6291394256aa758d74eec9ce0cfae8aea6475f2 (patch)
tree4fab7beaca627ae1448400ad3fe72b6fe08d7e7e /django
parent0bf627f0b2f868cdcc53ac12cc7f390901d4b83d (diff)
Refs #29887, Refs #24212 -- Added servers configuration hook for memcached backends.
The servers property can be overridden to allow memcached backends to alter the server configuration prior to it being passed to instantiate the client. This allows avoidance of documentation for per-backend differences, e.g. stripping the 'unix:' prefix for pylibmc.
Diffstat (limited to 'django')
-rw-r--r--django/core/cache/backends/memcached.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
index ed3f2af492..6a7ced6073 100644
--- a/django/core/cache/backends/memcached.py
+++ b/django/core/cache/backends/memcached.py
@@ -26,12 +26,16 @@ class BaseMemcachedCache(BaseCache):
self._class = library.Client
self._options = params.get('OPTIONS') or {}
+ @property
+ def client_servers(self):
+ return self._servers
+
@cached_property
def _cache(self):
"""
Implement transparent thread-safe access to a memcached client.
"""
- return self._class(self._servers, **self._options)
+ return self._class(self.client_servers, **self._options)
def get_backend_timeout(self, timeout=DEFAULT_TIMEOUT):
"""
@@ -192,6 +196,13 @@ class PyLibMCCache(BaseMemcachedCache):
import pylibmc
super().__init__(server, params, library=pylibmc, value_not_found_exception=pylibmc.NotFound)
+ @property
+ def client_servers(self):
+ output = []
+ for server in self._servers:
+ output.append(server[5:] if server.startswith('unix:') else server)
+ return output
+
def touch(self, key, timeout=DEFAULT_TIMEOUT, version=None):
key = self.make_key(key, version=version)
self.validate_key(key)