Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#1509 closed enhancement (fixed)

[patch] add anonymous-only caching to CacheMiddleware

Reported by: matt Owned by: Jacob
Component: Core (Cache system) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Here is a patch against trunk's django.middleware.cache.CacheMiddleware to optionally only cache anonymously requested (non-logged-in user) pages. Since rendered pages may contain user-specific information if they are logged in, caching those site-wide is often a bad idea. With this mdified middleware and CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True in your settings file, django can cache your non-logged in pages while serving up non-cached pages to logged in users.

I'm not a huge fan of CACHE_MIDDLEWARE_ANONYMOUS_ONLY so if someone thinks of a better name for it, feel free.

Attachments (1)

anonymous_caching.patch (2.2 KB) - added by matt 11 years ago.
patch for caching anonymous-only

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by matt

Attachment: anonymous_caching.patch added

patch for caching anonymous-only

comment:1 Changed 10 years ago by Malcolm Tredinnick

I'm not a fan of this way of implementing this. I would prefer a view decorator function to indicate this sort of thing. It feels like more of a per-view thing than a per-project thing to me.

comment:2 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [3395]) Added a CACHE_MIDDLEWARE_ANONYMOUS_ONLY setting which makes the cache ignore pages served to authenticated users. Fixes #1509 (thanks, Matt).

Also added a FAQ entry about using this setting to avoid caching of the admin interface.

Note: See TracTickets for help on using tickets.
Back to Top