Ticket #13686: 13686_14703_unicode_in_memcached_backend_r14757.diff

File 13686_14703_unicode_in_memcached_backend_r14757.diff, 2.0 KB (added by Alexey Smolsky, 14 years ago)

Extended patch with fix for #14703

  • django/core/cache/backends/memcached.py

     
    4040
    4141    def add(self, key, value, timeout=0, version=None):
    4242        key = self.make_key(key, version=version)
    43         if isinstance(value, unicode):
    44             value = value.encode('utf-8')
    4543        return self._cache.add(key, value, self._get_memcache_timeout(timeout))
    4644
    4745    def get(self, key, default=None, version=None):
     
    106104        safe_data = {}
    107105        for key, value in data.items():
    108106            key = self.make_key(key, version=version)
    109             if isinstance(value, unicode):
    110                 value = value.encode('utf-8')
    111107            safe_data[key] = value
    112108        self._cache.set_multi(safe_data, self._get_memcache_timeout(timeout))
    113109
  • tests/regressiontests/cache/tests.py

     
    315315            u'Iñtërnâtiônàlizætiøn': u'Iñtërnâtiônàlizætiøn2',
    316316            u'ascii': {u'x' : 1 }
    317317            }
     318        # Test `set`
    318319        for (key, value) in stuff.items():
    319320            self.cache.set(key, value)
    320321            self.assertEqual(self.cache.get(key), value)
    321322
     323        # Test `add`
     324        for (key, value) in stuff.items():
     325            self.cache.delete(key)
     326            self.cache.add(key, value)
     327            self.assertEqual(self.cache.get(key), value)
     328
     329        # Test `set_many`
     330        for (key, value) in stuff.items():
     331            self.cache.delete(key)
     332        self.cache.set_many(stuff)
     333        for (key, value) in stuff.items():
     334            self.assertEqual(self.cache.get(key), value)
     335
    322336    def test_binary_string(self):
    323337        # Binary strings should be cachable
    324338        from zlib import compress, decompress
Back to Top