Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15260 closed (fixed)

CACHE_MIDDLEWARE_ANONYMOUS_ONLY doesn't do anything when used with @cache_page in Django 1.2.5

Reported by: brodie Owned by: nobody
Component: Core (Cache system) Version: 1.2
Severity: Keywords: session vary cookie blocker regression
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

As of [15382], setting CACHE_MIDDLEWARE_ANONYMOUS_ONLY to True and using @cache_page on a view will unconditionally cache the view's response, even for logged in users, and even when request.user is accessed.

For example:

@cache_page(60 * 15)
def view(request):
    request.user
    return HttpResponse('')

The response will be cached unconditionally, even for logged in requests. The headers will look like this:

[('Expires', 'Thu, 10 Feb 2011 02:53:28 GMT'),
 ('Vary', 'Cookie'),
 ('Last-Modified', 'Thu, 10 Feb 2011 02:38:28 GMT'),
 ('ETag', '"ee11cbb19052e40b07aac0ca060c23ee"'),
 ('Cache-Control', 'max-age=900'),
 ('Content-Type', 'text/html; charset=utf-8')]

Setting the decorators to @vary_on_cookie and then @cache_page results in the same thing. Flipping the order and setting them to @cache_page followed by @vary_on_cookie results in the correct behavior (no caching).

Also, the release notes for 1.2.5 make no mention of the changes introduced by [15382].

Attachments (2)

test-cache-anonymous-only.patch (3.0 KB) - added by brodie 3 years ago.
cache-page-fix.patch (4.7 KB) - added by brodie 3 years ago.

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by brodie

comment:1 Changed 3 years ago by russellm

  • Keywords blocker regression added
  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 3 years ago by brodie

comment:2 Changed 3 years ago by brodie

  • Has patch set

comment:3 Changed 3 years ago by carljm

  • Resolution set to fixed
  • Status changed from new to closed

In [15559]:

Fixed #15260 -- Ensured that CACHE_MIDDLEWARE_ANONYMOUS_ONLY is effective with the cache_page decorator, not only the middleware. Thanks to brodie for report and draft patch.

comment:4 Changed 3 years ago by carljm

In [15560]:

[1.2.X] Fixed #15260 -- Ensured that CACHE_MIDDLEWARE_ANONYMOUS_ONLY is effective with the cache_page decorator, not only the middleware. Thanks to brodie for report and draft patch.

Backport of r15559 from trunk.

comment:5 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.