Ticket #12399: django_memcache.patch

File django_memcache.patch, 1.3 KB (added by Karataev Pavel, 14 years ago)

fix in cache.backend level

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

     
    11"Memcached cache backend"
    22
     3import time
     4
    35from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
    46from django.utils.encoding import smart_unicode, smart_str
    57
     
    3436    def set(self, key, value, timeout=0):
    3537        if isinstance(value, unicode):
    3638            value = value.encode('utf-8')
    37         self._cache.set(smart_str(key), value, timeout or self.default_timeout)
     39        timeout = timeout or self.default_timeout
     40        if timeout and timeout > 2592000: # 60*60*24*30, 30 days
     41            # See http://code.google.com/p/memcached/wiki/FAQ
     42            # "You can set expire times up to 30 days in the future. After that
     43            # memcached interprets it as a date, and will expire the item after
     44            # said date. This is a simple (but obscure) mechanic."
     45            #
     46            # This means that we have to switch to absolute timestamps.
     47            timeout += int(time.time())
     48        self._cache.set(smart_str(key), value, timeout)
    3849
    3950    def delete(self, key):
    4051        self._cache.delete(smart_str(key))
Back to Top