gpt4 book ai didi

python - 在 Django/python 中,如何将内存缓存设置为无限时间?

转载 作者:太空狗 更新时间:2023-10-29 19:33:27 24 4
gpt4 key购买 nike

cache.set(key, value, 9999999)

但这不是无限时间...

最佳答案

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 :

What are the limits on setting expire time? (why is there a 30 day limit?)

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.

关于python - 在 Django/python 中,如何将内存缓存设置为无限时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2917290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com