Ticket #7460: django_memcache_backend_7460.diff

File django_memcache_backend_7460.diff, 1.4 KB (added by trbs, 7 years ago)
  • django/core/cache/backends/memcached.py

    diff -r 00e4e4b60c7f django/core/cache/backends/memcached.py
    a b  
    1717        self._cache = memcache.Client(server.split(';'))
    1818
    1919    def add(self, key, value, timeout=0):
    20         return self._cache.add(key.encode('ascii', 'ignore'), value, timeout or self.default_timeout)
     20        return self._cache.add(smart_str(key.replace(" ", "_")), value, timeout or self.default_timeout)
    2121
    2222    def get(self, key, default=None):
    23         val = self._cache.get(smart_str(key))
     23        val = self._cache.get(smart_str(key.replace(" ", "_")))
    2424        if val is None:
    2525            return default
    2626        else:
     
    3232    def set(self, key, value, timeout=0):
    3333        if isinstance(value, unicode):
    3434            value = value.encode('utf-8')
    35         self._cache.set(smart_str(key), value, timeout or self.default_timeout)
     35        self._cache.set(smart_str(key.replace(" ", "_")), value, timeout or self.default_timeout)
    3636
    3737    def delete(self, key):
    38         self._cache.delete(smart_str(key))
     38        self._cache.delete(smart_str(key.replace(" ", "_")))
    3939
    4040    def get_many(self, keys):
    41         return self._cache.get_multi(map(smart_str,keys))
     41        return self._cache.get_multi([smart_str(k.replace(" ", "_")) for k in keys])
    4242
    4343    def close(self, **kwargs):
    4444        self._cache.disconnect_all()
Back to Top