Kaydet (Commit) 5a9b2bce authored tarafından Bas Peschier's avatar Bas Peschier Kaydeden (comit) Aymeric Augustin

Fixed #19810 -- MemcachedCache now uses pickle.HIGHEST_PROTOCOL

üst d7e835f7
"Memcached cache backend"
import time
import pickle
from threading import local
from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
......@@ -146,6 +147,12 @@ class MemcachedCache(BaseMemcachedCache):
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):
......
......@@ -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.
......
......@@ -12,6 +12,7 @@ import string
import tempfile
import time
import warnings
import pickle
from django.conf import settings
from django.core import management
......@@ -984,6 +985,18 @@ class MemcachedCacheTests(unittest.TestCase, BaseCacheTests):
# 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):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment