Ticket #6988: django-memcached.patch

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

    # HG changeset patch
    # User Simon Law <simon@akoha.org>
    # Date 1207702167 14400
    # Node ID ee193c85cda9c596152a230286b1052c7399b01f
    # Parent  8f35d9182ce1fccc95b09f6bfedd0ff7a9c20f34
    #2107 - memcached cache behaves the same as other caches when timeout=0
    
    diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
    a b class CacheClass(BaseCache):  
    1717        self._cache = memcache.Client(server.split(';'))
    1818
    1919    def add(self, key, value, timeout=0):
    20         self._cache.add(key.encode('ascii', 'ignore'), value, timeout or self.default_timeout)
     20        timeout = timeout or self.default_timeout
     21        if timeout:
     22            self._cache.add(key.encode('ascii', 'ignore'), value, timeout)
    2123
    2224    def get(self, key, default=None):
    2325        val = self._cache.get(smart_str(key))
    class CacheClass(BaseCache):  
    3234    def set(self, key, value, timeout=0):
    3335        if isinstance(value, unicode):
    3436            value = value.encode('utf-8')
    35         self._cache.set(smart_str(key), value, timeout or self.default_timeout)
     37        timeout = timeout or self.default_timeout
     38        if timeout:
     39            self._cache.set(smart_str(key), value, timeout)
    3640
    3741    def delete(self, key):
    3842        self._cache.delete(smart_str(key))
Back to Top