Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #18770 -- memcached cache backend expects byte strings as keys

Thanks thecore for the report.
  • Loading branch information...
commit 4e17f4589accf5be0954eebc41d36ef96125d47c 1 parent 607665a
@claudep claudep authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 django/core/cache/backends/
5 django/core/cache/backends/
@@ -6,6 +6,7 @@
from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
from django.utils import six
+from django.utils.encoding import smart_str
class BaseMemcachedCache(BaseCache):
def __init__(self, server, params, library, value_not_found_exception):
@@ -50,6 +51,10 @@ def _get_memcache_timeout(self, timeout):
timeout += int(time.time())
return int(timeout)
+ def make_key(self, key, version=None):
+ # Python 2 memcache requires the key to be a byte string.
+ return smart_str(super(BaseMemcachedCache, self).make_key(key, version))
def add(self, key, value, timeout=0, version=None):
key = self.make_key(key, version=version)
return self._cache.add(key, value, self._get_memcache_timeout(timeout))
Please sign in to comment.
Something went wrong with that request. Please try again.