Django

Code

Ticket #5813 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

CacheMiddleware should respect max-age

Reported by: SmileyChris Assigned to: nobody
Milestone: Component: Cache system
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

cache_middleware_respect_maxage.diff (4.5 kB) - added by SmileyChris on 10/24/07 19:28:07.

Change History

10/24/07 19:28:07 changed by SmileyChris

  • attachment cache_middleware_respect_maxage.diff added.

10/24/07 19:44:52 changed by SmileyChris

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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.

10/25/07 04:34:33 changed by anonymous

  • stage changed from Unreviewed to Ready for checkin.

10/25/07 04:34:58 changed by Simon G

oops, that was me.

11/29/07 10:57:18 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #5813 (CacheMiddleware should respect max-age)




Change Properties
Action