Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django cache framework. What is the difference between TIMEOUT and CACHE_MIDDLEWARE_SECONDS?

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?

like image 856
Alexander Avatar asked Oct 05 '14 12:10

Alexander


1 Answers

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.

like image 124
Wtower Avatar answered Oct 17 '22 04:10

Wtower