mirror of https://github.com/django/django.git
Fixed #11331 -- Stopped closing pylibmc connections after each request.
libmemcached manages its own connections, so isn't affected by refs #5133.
This commit is contained in:
parent
3e935aec6d
commit
f02dbbe1ae
|
@ -103,6 +103,7 @@ class BaseMemcachedCache(BaseCache):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def close(self, **kwargs):
|
def close(self, **kwargs):
|
||||||
|
# Many clients don't clean up connections properly.
|
||||||
self._cache.disconnect_all()
|
self._cache.disconnect_all()
|
||||||
|
|
||||||
def incr(self, key, delta=1, version=None):
|
def incr(self, key, delta=1, version=None):
|
||||||
|
@ -202,3 +203,8 @@ class PyLibMCCache(BaseMemcachedCache):
|
||||||
@cached_property
|
@cached_property
|
||||||
def _cache(self):
|
def _cache(self):
|
||||||
return self._lib.Client(self._servers, **self._options)
|
return self._lib.Client(self._servers, **self._options)
|
||||||
|
|
||||||
|
def close(self, **kwargs):
|
||||||
|
# libmemcached manages its own connections. Don't call disconnect_all()
|
||||||
|
# as it resets the failover state and creates unnecessary reconnects.
|
||||||
|
pass
|
||||||
|
|
|
@ -1156,6 +1156,10 @@ memcached_excluded_caches = {'cull', 'zero_cull'}
|
||||||
|
|
||||||
class BaseMemcachedTests(BaseCacheTests):
|
class BaseMemcachedTests(BaseCacheTests):
|
||||||
|
|
||||||
|
# By default it's assumed that the client doesn't clean up connections
|
||||||
|
# properly, in which case the backend must do so after each request.
|
||||||
|
should_disconnect_on_close = True
|
||||||
|
|
||||||
def test_location_multiple_servers(self):
|
def test_location_multiple_servers(self):
|
||||||
locations = [
|
locations = [
|
||||||
['server1.tld', 'server2:11211'],
|
['server1.tld', 'server2:11211'],
|
||||||
|
@ -1244,7 +1248,7 @@ class BaseMemcachedTests(BaseCacheTests):
|
||||||
# connection is closed when the request is complete.
|
# connection is closed when the request is complete.
|
||||||
with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect:
|
with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect:
|
||||||
signals.request_finished.send(self.__class__)
|
signals.request_finished.send(self.__class__)
|
||||||
self.assertIs(mock_disconnect.called, True)
|
self.assertIs(mock_disconnect.called, self.should_disconnect_on_close)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(MemcachedCache_params, "MemcachedCache backend not configured")
|
@unittest.skipUnless(MemcachedCache_params, "MemcachedCache backend not configured")
|
||||||
|
@ -1276,6 +1280,8 @@ class MemcachedCacheTests(BaseMemcachedTests, TestCase):
|
||||||
))
|
))
|
||||||
class PyLibMCCacheTests(BaseMemcachedTests, TestCase):
|
class PyLibMCCacheTests(BaseMemcachedTests, TestCase):
|
||||||
base_params = PyLibMCCache_params
|
base_params = PyLibMCCache_params
|
||||||
|
# libmemcached manages its own connections.
|
||||||
|
should_disconnect_on_close = False
|
||||||
|
|
||||||
# By default, pylibmc/libmemcached don't verify keys client-side and so
|
# By default, pylibmc/libmemcached don't verify keys client-side and so
|
||||||
# this test triggers a server-side bug that causes later tests to fail
|
# this test triggers a server-side bug that causes later tests to fail
|
||||||
|
|
Loading…
Reference in New Issue