I had the same question, and the existing answers still did not clarify me. So I decided to dive into the source code. Yay for open source!
CACHE_MIDDLEWARE_SECONDS used by the UpdateCacheMiddleware . It sets the Cache-Control ( max-age ) CACHE_MIDDLEWARE_SECONDS to CACHE_MIDDLEWARE_SECONDS if the view has not set it yet, which affects the client-side cache. Here is the code:
self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS # ... timeout = get_max_age(response) if timeout is None: timeout = self.cache_timeout patch_response_headers(response, timeout)
(Please note that I cut out the code and edge angles to make it faster to read, you can of course read the full source code).
It also stores the response in the server-side cache, using the same timeout value that comes from MIDDLEWARE_CACHE_SECONDS , overriding the TIMEOUT parameter if it was set: ( context )
if timeout: cache_key = learn_cache_key(request, response, timeout, self.key_prefix, cache=self.cache) self.cache.set(cache_key, response, timeout)
The middleware tool is FetchFromCacheMiddleware with UpdateCacheMiddleware and uses the server-side cache values set by the latter, therefore it is indirectly affected by CACHE_MIDDLEWARE_SECONDS .
Alternative middleware CacheMiddleware also uses CACHE_MIDDLEWARE_SECONDS . This should not affect you if you are not using CacheMiddleware .
So what is the TIMEOUT installation point? I suppose this is the default value that is used if you write directly to the cache, but it is not used by the previously mentioned middleware. For instance:
from django.core.cache import cache cache.set('my_key', 'my_value')