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

标签 python django memcached

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/

相关文章:

python - 在 PyTorch 中,grad_fn 属性究竟存储了什么以及它是如何使用的?

python - 如何在Python中的Google Cloud Function中运行子流程

python - xlsxwriter 无法将超过 1,048,576 行写入多个表和工作表

python - 避免浮点均值误差

python - Django 模型 .get 失败,但 .filter 和 .all 有效 - 对象存在于数据库中

php - 如何从 PHP 过渡到 Python Django?

php - memcached 数据缓存的设计模式

python - 将模型字段序列化为嵌套对象/字典

c++ - 将操作数据存储在 memcached 中是个好主意吗?

perl - 如何将复杂的 Perl 对象存储到 Memcached 中?