Ticket #7460: memcachedkeys.diff
File memcachedkeys.diff, 1.7 KB (added by , 16 years ago) |
---|
-
django/core/cache/backends/memcached.py
1 1 "Memcached cache backend" 2 2 3 3 from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError 4 from django.utils.encoding import smart_unicode, smart_str 4 from django.utils.encoding import smart_unicode 5 from django.utils.http import urlquote 5 6 6 7 try: 7 8 import cmemcache as memcache … … 17 18 self._cache = memcache.Client(server.split(';')) 18 19 19 20 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) 21 22 22 23 def get(self, key, default=None): 23 val = self._cache.get( smart_str(key))24 val = self._cache.get(urlquote(key)) 24 25 if val is None: 25 26 return default 26 27 else: … … 32 33 def set(self, key, value, timeout=0): 33 34 if isinstance(value, unicode): 34 35 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) 36 37 37 38 def delete(self, key): 38 self._cache.delete( smart_str(key))39 self._cache.delete(urlquote(key)) 39 40 40 41 def get_many(self, keys): 41 return self._cache.get_multi(map( smart_str,keys))42 return self._cache.get_multi(map(urlquote, keys)) 42 43 43 44 def close(self, **kwargs): 44 45 self._cache.disconnect_all() 45