diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
index e254527..1e4e482 100644
a
|
b
|
class CacheClass(BaseCache):
|
43 | 43 | val = self._cache.get(smart_str(key)) |
44 | 44 | if val is None: |
45 | 45 | return default |
46 | | else: |
47 | | if isinstance(val, basestring): |
48 | | return smart_unicode(val) |
49 | | else: |
50 | | return val |
| 46 | return val |
51 | 47 | |
52 | 48 | def set(self, key, value, timeout=0): |
53 | | if isinstance(value, unicode): |
54 | | value = value.encode('utf-8') |
55 | 49 | self._cache.set(smart_str(key), value, self._get_memcache_timeout(timeout)) |
56 | 50 | |
57 | 51 | def delete(self, key): |
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index 5d8d039..585492c 100644
a
|
b
|
class BaseCacheTests(object):
|
293 | 293 | self.cache.set(key, value) |
294 | 294 | self.assertEqual(self.cache.get(key), value) |
295 | 295 | |
| 296 | def test_binary_string(self): |
| 297 | # Binary strings should be cachable |
| 298 | from zlib import compress, decompress |
| 299 | value = 'value_to_be_compressed' |
| 300 | compressed_value = compress(value) |
| 301 | self.cache.set('binary1', compressed_value) |
| 302 | compressed_result = self.cache.get('binary1') |
| 303 | self.assertEqual(compressed_value, compressed_result) |
| 304 | self.assertEqual(value, decompress(compressed_result)) |
| 305 | |
296 | 306 | def test_set_many(self): |
297 | 307 | # Multiple keys can be set using set_many |
298 | 308 | self.cache.set_many({"key1": "spam", "key2": "eggs"}) |