Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19810 -- MemcachedCache now uses pickle.HIGHEST_PROTOCOL

  • Loading branch information...
commit 5a9b2bce242bd2f8a9fed6ac735406ce68b10738 1 parent d7e835f
Bas Peschier bpeschier authored aaugustin committed
7 django/core/cache/backends/memcached.py
View
@@ -1,6 +1,7 @@
"Memcached cache backend"
import time
+import pickle
from threading import local
from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
@@ -146,6 +147,12 @@ def __init__(self, server, params):
library=memcache,
value_not_found_exception=ValueError)
+ @property
+ def _cache(self):
+ if getattr(self, '_client', None) is None:
+ self._client = self._lib.Client(self._servers, pickleProtocol=pickle.HIGHEST_PROTOCOL)
+ return self._client
+
class PyLibMCCache(BaseMemcachedCache):
"An implementation of a cache binding using pylibmc"
def __init__(self, server, params):
3  docs/releases/1.6.txt
View
@@ -89,6 +89,9 @@ Minor features
:class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
attribute (equivalent to the URL the response will redirect to).
+* The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
+ protocol available.
+
* Added the :attr:`django.db.models.ForeignKey.db_constraint`
option.
13 tests/regressiontests/cache/tests.py
View
@@ -12,6 +12,7 @@
import tempfile
import time
import warnings
+import pickle
from django.conf import settings
from django.core import management
@@ -984,6 +985,18 @@ def test_invalid_keys(self):
# memcached limits key length to 250
self.assertRaises(Exception, self.cache.set, 'a' * 251, 'value')
+ # Explicitly display a skipped test if no configured cache uses MemcachedCache
+ @unittest.skipUnless(
+ any(cache['BACKEND'] == 'django.core.cache.backends.memcached.MemcachedCache'
+ for cache in settings.CACHES.values()),
+ "cache with python-memcached library not available")
+ def test_memcached_uses_highest_pickle_version(self):
+ # Regression test for #19810
+ for cache_key, cache in settings.CACHES.items():
+ if cache['BACKEND'] == 'django.core.cache.backends.memcached.MemcachedCache':
+ self.assertEqual(get_cache(cache_key)._cache.pickleProtocol,
+ pickle.HIGHEST_PROTOCOL)
+
class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.