From 4e17f4589accf5be0954eebc41d36ef96125d47c Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 15 Aug 2012 16:56:33 +0200 Subject: [PATCH] Fixed #18770 -- memcached cache backend expects byte strings as keys Thanks thecore for the report. --- django/core/cache/backends/memcached.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index e7724f1b918..75ce26d20e0 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -6,6 +6,7 @@ from threading import local 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 @@ class BaseMemcachedCache(BaseCache): 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))