cache.set(key, value, 9999999)
但这不是无限的时间......
答案 0 :(得分:12)
def _get_memcache_timeout(self, timeout):
"""
Memcached deals with long (> 30 days) timeouts in a special
way. Call this function to obtain a safe value for your timeout.
"""
timeout = timeout or self.default_timeout
if timeout > 2592000: # 60*60*24*30, 30 days
# See http://code.google.com/p/memcached/wiki/FAQ
# "You can set expire times up to 30 days in the future. After that
# memcached interprets it as a date, and will expire the item after
# said date. This is a simple (but obscure) mechanic."
#
# This means that we have to switch to absolute timestamps.
timeout += int(time.time())
return timeout
来自FAQ:
设置过期时间有哪些限制? (为什么有30天的限制?)
您可以将过期时间设置为最多30天。之后,memcached将其解释为日期,并在该日期之后使该项目到期。这是一个简单(但不起眼)的机制。
答案 1 :(得分:9)
答案 2 :(得分:6)
通过设置timeout=None
答案 3 :(得分:-6)
另一种简单的技术是将生成的HTML写入磁盘上的文件,并将其用作缓存。它并不难实现,并且它可以很好地用作基于文件的缓存,它永远不会过期,非常透明等等。
这不是django方式,但效果很好。