Tested against Django 1.2.x
Note: this project has just been moved from Google Code, with some modifications, so consider it untested.
- Add
django_cache_middleware
to the top of yoursettings.INSTALLED_APPS
.
This will monkey-patch Django to automatically use this library's middleware
instead of django.middleware.cache.CacheMiddleware
- assuming that is
already in your settings.MIDDLEWARE_CLASSES
.
There are some aspects of Django's caching middleware that I felt could be improved:
- It doesn't send
304 Not Modified
responses when there are appropriate cached response. - When the
request.user
object is accessed, it varies the cache key based on the user's cookies. This results in separate cached responses for each individual user. It even caches responses individually for anonymous users!
- Improved caching middleware
- Returns "304 Not Modified" responses when it can, saving bandwidth and speeding up the user experience. Caches more situations effectively than Django's built-in middleware.
- @vary_on_view decorator
- Provides specific control over view caching, without you having to write any caching code.
- Strip cookies middleware
- Google Analytics stops the cache middleware from working correctly, and this middleware will solve that problem.
A scenario that demonstrates the usefulness of improved-django-caching