Opened 48 minutes ago

Last modified 43 minutes ago

#37290 assigned New feature

Update UpdateCacheMiddleware to mark a response as cached

Reported by: Tim Schilling Owned by: Django Sprints
Component: Core (Cache system) Version: dev
Severity: Normal Keywords: headers, caching, cache_page
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When caching a response, UpdateCacheMiddleware could mark the response such that other logic can determine if the response was already cached. This would allow us to emit warnings that responses are cached unexpectedly. The point here is to help Django apps know when using @cache_page that it's caching the response before other middlewares or decorators are able to weigh in. This is related to #15855

The decorator_from_middleware that @cache_page uses, and the challenges of it was discussed here: https://groups.google.com/g/django-developers/c/-W6YIlT75cM

The following should be updated to check if a response has been cached to emit a warning.

  • @csrf_protect
  • @patch_vary_headers
  • @vary_on_headers (vary_on_cookie)
  • ContentSecurityPolicyMiddleware.process_response
  • HttpResponseBase.set_cookie (maybe? this is due to SessionMiddleware.process_response)

I think the warning messages may need to be tailored for the particular cases.

Change History (1)

comment:1 by Jacob Walls, 43 minutes ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

Great idea!

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