Django缓存框架。 TIMEOUT和CACHE_MIDDLEWARE_SECONDS有什么区别? [英] Django cache framework. What is the difference between TIMEOUT and CACHE_MIDDLEWARE_SECONDS?

查看:797
本文介绍了Django缓存框架。 TIMEOUT和CACHE_MIDDLEWARE_SECONDS有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用数据库缓存在Django中设置缓存。有两个设置TIMEOUT和CACHE_MIDDLEWARE_SECONDS可以控制页面被缓存多长时间。这两个设置有什么区别?

解决方案

确实,相应的文档没有充分解释差异。



第一个选项 CACHES TIMEOUT Django缓存框架,缓存参数。这是在$ code> cache.set()等函数中使用的默认过期时间,如果没有提供。稍后在低级缓存API使用情况中记录。



后者 CACHE_MIDDLEWARE_SECONDS Django缓存框架,每个站点缓存。因此,假设它是所有页面的默认过期时间,可能是安全的,就好像 @cache_page(settings.CACHE_MIDDLEWARE_SECONDS) =https://docs.djangoproject.com/en/1.8/topics/cache/#the-per-view-cache =nofollow>每个视图基础。


I have been setting up caching in Django using a database cache. There are two settings TIMEOUT and CACHE_MIDDLEWARE_SECONDS that control how long a page is cached for. What is the difference between these two settings?

解决方案

Indeed the respective documentation does not adequately explain the differences.

The first option, CACHES: TIMEOUT is introduced in Django cache framework, Cache arguments. It is the default expiration time that is used in functions such as cache.set(), if none else is provided. This is later documented in the low-level cache API usage.

The latter, CACHE_MIDDLEWARE_SECONDS is introduced in Django cache framework, The per-site cache. Therefore it might be safe to assume that it is the default expiration time for all pages, as if the @cache_page(settings.CACHE_MIDDLEWARE_SECONDS) would have been used on a per-view basis.

这篇关于Django缓存框架。 TIMEOUT和CACHE_MIDDLEWARE_SECONDS有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆