Django has a caching framework that might be better for this:

https://docs.djangoproject.com/en/dev/topics/cache/#django.views.decorators.cache.cache_page

You could wrap that a bit to handle the authenticated vs. anonymous pretty easily, I think.