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

Alexander picture Alexander · Oct 5, 2014 · Viewed 7.1k times · Source

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?

Answer

Wtower picture Wtower · Jun 16, 2015

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.