If you use CacheMiddleware, it’s important to put it in the right place within the MIDDLEWARE_CLASSES setting, because the cache middleware needs to know the headers by which to vary the cache storage. Put the CacheMiddleware after any middlewares that might add something to the Vary header, including the following:
- UpdateCacheMiddleware
- GZipMiddleware
- ConditionalGetMiddleware
- SessionMiddleware
- LocaleMiddleware
- CommonMiddleware
- CsrfViewMiddleware
- AuthenticationMiddleware
- MessageMiddleware
- FetchFromCacheMiddleware
- FlatpageFallbackMiddleware
- RedirectFallbackMiddleware