The per-site cache
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 ...
Get Mastering Django: Core now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.