Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed #19810 -- MemcachedCache now uses pickle.HIGHEST_PROTOCOL #821

Closed
wants to merge 1 commit into from

2 participants

@bpeschier

Added a test to @fernandogrd's pull request (#720)

@apollo13
Owner

Commited in 5a9b2bc

@apollo13 apollo13 closed this
@bpeschier bpeschier deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 django/core/cache/backends/memcached.py
@@ -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):
View
13 tests/regressiontests/cache/tests.py
@@ -12,6 +12,7 @@
import tempfile
import time
import warnings
+import pickle
from django.conf import settings
from django.core import management
@@ -977,6 +978,18 @@ def test_invalid_keys(self):
# memcached limits key length to 250
self.assertRaises(Exception, self.cache.set, 'a' * 251, 'value')
+ @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):
+ for cache_key, cache in settings.CACHES.items():
+ if cache['BACKEND'] == 'django.core.cache.backends.memcached.MemcachedCache':
+ break
+
+ cache = get_cache(cache_key)._cache # get client for library
+ self.assertEqual(cache.pickleProtocol, pickle.HIGHEST_PROTOCOL) # check library pickle version
+
class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
"""
Something went wrong with that request. Please try again.