Author: jacob
Date: 2010-03-01 14:14:18 -0600 (Mon, 01 Mar 2010)
New Revision: 12638

Modified:
   django/branches/releases/1.1.X/django/core/cache/backends/memcached.py
   django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py
Log:
[1.1.X] Fixed #11012: don't needless convert cache values to unicode.

This means you can now successfully store binary blogs, such as compressed data,
in the cache.

Thanks to Matt Croydon for the final patch.

Backport of [12637] from trunk.

Modified: django/branches/releases/1.1.X/django/core/cache/backends/memcached.py
===================================================================
--- django/branches/releases/1.1.X/django/core/cache/backends/memcached.py      
2010-03-01 20:11:24 UTC (rev 12637)
+++ django/branches/releases/1.1.X/django/core/cache/backends/memcached.py      
2010-03-01 20:14:18 UTC (rev 12638)
@@ -43,15 +43,9 @@
         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):

Modified: django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py
===================================================================
--- django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py 
2010-03-01 20:11:24 UTC (rev 12637)
+++ django/branches/releases/1.1.X/tests/regressiontests/cache/tests.py 
2010-03-01 20:14:18 UTC (rev 12638)
@@ -278,6 +278,16 @@
             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_long_timeout(self):
         '''
         Using a timeout greater than 30 days makes memcached think

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to