Ticket #7460: memcachedkeys.diff

File memcachedkeys.diff, 1.7 KB (added by Julian Bez, 16 years ago)

Apply percent-encoding to keys

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

     
    11"Memcached cache backend"
    22
    33from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
    4 from django.utils.encoding import smart_unicode, smart_str
     4from django.utils.encoding import smart_unicode
     5from django.utils.http import urlquote
    56
    67try:
    78    import cmemcache as memcache
     
    1718        self._cache = memcache.Client(server.split(';'))
    1819
    1920    def add(self, key, value, timeout=0):
    20         return self._cache.add(key.encode('ascii', 'ignore'), value, timeout or self.default_timeout)
     21        return self._cache.add(urlquote(key), value, timeout or self.default_timeout)
    2122
    2223    def get(self, key, default=None):
    23         val = self._cache.get(smart_str(key))
     24        val = self._cache.get(urlquote(key))
    2425        if val is None:
    2526            return default
    2627        else:
     
    3233    def set(self, key, value, timeout=0):
    3334        if isinstance(value, unicode):
    3435            value = value.encode('utf-8')
    35         self._cache.set(smart_str(key), value, timeout or self.default_timeout)
     36        self._cache.set(urlquote(key), value, timeout or self.default_timeout)
    3637
    3738    def delete(self, key):
    38         self._cache.delete(smart_str(key))
     39        self._cache.delete(urlquote(key))
    3940
    4041    def get_many(self, keys):
    41         return self._cache.get_multi(map(smart_str,keys))
     42        return self._cache.get_multi(map(urlquote, keys))
    4243
    4344    def close(self, **kwargs):
    4445        self._cache.disconnect_all()
    45 
Back to Top