Opened 17 years ago

Closed 17 years ago

#5813 closed (fixed)

CacheMiddleware should respect max-age

Reported by: Chris Beaven Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This came up in IRC today, someone (K0001) wanted to use the per-site middleware but disable caching for a specific view. It seems like the django.views.decorators.cache.never_cache decorator should work but it wasn't.

The reason is because currently the cache middleware doesn't bother looking to see if an expiry age was set by the response, it just uses the CACHE_MIDDLEWARE_SECONDS setting.

Attachments (1)

cache_middleware_respect_maxage.diff (4.5 KB ) - added by Chris Beaven 17 years ago.

Download all attachments as: .zip

Change History (5)

by Chris Beaven, 17 years ago

comment:1 by Chris Beaven, 17 years ago

For example (assuming you have the middleware turned on):

from django.views.decorators.cache import never_cache, cache_control

def test_cache(request):
    from datetime import datetime
    from django.http import HttpResponse
    return HttpResponse(str(datetime.now()))

cached_view = test_cache
no_cache_view = never_cache(test_cache)
short_cache_view = cache_control(max_age=5)(test_cache)

When/if this is committed it should probably be noted on BackwardsIncompatibleChanges that the per-site cache logic has changed.

comment:2 by anonymous, 17 years ago

Triage Stage: UnreviewedReady for checkin

comment:3 by Simon G, 17 years ago

oops, that was me.

comment:4 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [6736]) Fixed #5813 -- Taught the CacheMiddleware to respect any max-age HTTP header
when setting the expiry time. Thanks, SmileyChris.

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