Ticket #12399: django_memcache.patch
File django_memcache.patch, 1.3 KB (added by , 15 years ago) |
---|
-
TabularUnified django/core/cache/backends/memcached.py
1 1 "Memcached cache backend" 2 2 3 import time 4 3 5 from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError 4 6 from django.utils.encoding import smart_unicode, smart_str 5 7 … … 34 36 def set(self, key, value, timeout=0): 35 37 if isinstance(value, unicode): 36 38 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) 38 49 39 50 def delete(self, key): 40 51 self._cache.delete(smart_str(key))