diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index e254527cea..1e4e482b11 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -43,15 +43,9 @@ class CacheClass(BaseCache): val = self._cache.get(smart_str(key)) if val is None: return default - else: - if isinstance(val, basestring): - return smart_unicode(val) - else: - return val + return val def set(self, key, value, timeout=0): - if isinstance(value, unicode): - value = value.encode('utf-8') self._cache.set(smart_str(key), value, self._get_memcache_timeout(timeout)) def delete(self, key): diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index 9ed93e8750..109374c46c 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -295,6 +295,16 @@ class BaseCacheTests(object): self.cache.set(key, value) self.assertEqual(self.cache.get(key), value) + def test_binary_string(self): + # Binary strings should be cachable + from zlib import compress, decompress + value = 'value_to_be_compressed' + compressed_value = compress(value) + self.cache.set('binary1', compressed_value) + compressed_result = self.cache.get('binary1') + self.assertEqual(compressed_value, compressed_result) + self.assertEqual(value, decompress(compressed_result)) + def test_set_many(self): # Multiple keys can be set using set_many self.cache.set_many({"key1": "spam", "key2": "eggs"})