How can I configure Flask-Cache with infinite timeout

会有一股神秘感。 提交于 2019-12-10 03:54:32

问题


In the Flask-Cache documentation all the examples use a finite timeout.

I'd like to never refresh the cache while the app is running. Is this possible, and if so how do I do it?


回答1:


Flask-Cache uses werkzeug.contrib.cache behind the scenes. From the documentation it's made clear that

A timeout of 0 indicates that the cache never expires.

So yes, infinite caching is supported and can be turned on by setting the timeout to zero.




回答2:


There does not seem to be anything listed in the docs. I have used the following and it works fine.

     cache = Cache(webapp, config={
         'CACHE_TYPE': 'filesystem',
         'CACHE_DIR': 'cache-dir', 
         'CACHE_DEFAULT_TIMEOUT': 922337203685477580,
         'CACHE_THRESHOLD': 922337203685477580
     })

That is way more years than you will need to worry about so for all intents and purposes, let's call that infinite.



来源:https://stackoverflow.com/questions/17938711/how-can-i-configure-flask-cache-with-infinite-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!