Once the cache is set up, the simplest way to use caching is to cache your entire site. You'll need to add 'django.middleware.cache.UpdateCacheMiddleware'
and 'django.middleware.cache.FetchFromCacheMiddleware'
to your MIDDLEWARE_CLASSES
setting, as in this example:
MIDDLEWARE_CLASSES = [ 'django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware', ]
Note
No, that's not a typo: the update middleware must be first in the list, and the fetch middleware must be last. The details are a bit obscure, but see Order of MIDDLEWARE_CLASSES) in the next chapter if you'd like the full story.
Then, add the following required settings to your Django settings file:
CACHE_MIDDLEWARE_ALIAS
: The cache alias to use for storage.CACHE_MIDDLEWARE_SECONDS
: The number of seconds each page should be cached.CACHE_MIDDLEWARE_KEY_PREFIX
-: If the cache is shared across multiple...