在Django / python中,如何将memcache设置为无限时间? [英] In Django/python, how do I set the memcache to infinite time?
本文介绍了在Django / python中,如何将memcache设置为无限时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
cache.set(key, value, 9999999)
但这不是无限的时间...
But this is not infinite time...
推荐答案
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
而从常见问题解答:
设置到期时间有什么限制(为什么有30天的限制?)
What are the limits on setting expire time? (why is there a 30 day limit?)
您可以设定逾期30天的到期时间,之后memcache将其解释为日期,并在该日期之后到期,这是一个简单(但模糊的)技工。
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.
这篇关于在Django / python中,如何将memcache设置为无限时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文