Ticket #6988: django-memcached.2.patch

File django-memcached.2.patch, 1.3 KB (added by Simon Law <simon@…>, 11 years ago)
  • django/core/cache/backends/memcached.py

    diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
    a b class CacheClass(BaseCache): 
    1616        BaseCache.__init__(self, params)
    1717        self._cache = memcache.Client(server.split(';'))
    1818
    19     def add(self, key, value, timeout=0):
    20         self._cache.add(key.encode('ascii', 'ignore'), value, timeout or self.default_timeout)
     19    def add(self, key, value, timeout=None):
     20        if timeout is None:
     21            timeout = self.default_timeout
     22        if timeout:
     23            self._cache.add(key.encode('ascii', 'ignore'), value, timeout)
    2124
    2225    def get(self, key, default=None):
    2326        val = self._cache.get(smart_str(key))
    class CacheClass(BaseCache): 
    2932            else:
    3033                return val
    3134
    32     def set(self, key, value, timeout=0):
     35    def set(self, key, value, timeout=None):
    3336        if isinstance(value, unicode):
    3437            value = value.encode('utf-8')
    35         self._cache.set(smart_str(key), value, timeout or self.default_timeout)
     38        if timeout is None:
     39            timeout = self.default_timeout
     40        if timeout:
     41            self._cache.set(smart_str(key), value, timeout)
    3642
    3743    def delete(self, key):
    3844        self._cache.delete(smart_str(key))
Back to Top