Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#1509 closed enhancement (fixed)

[patch] add anonymous-only caching to CacheMiddleware

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

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 19 years ago.
patch for caching anonymous-only

Download all attachments as: .zip

Change History (3)

by matt, 19 years ago

Attachment: anonymous_caching.patch added

patch for caching anonymous-only

comment:1 by Malcolm Tredinnick, 18 years ago

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 by Jacob, 18 years ago

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