Opened 2 months ago

Last modified 9 days ago

#37290 assigned New feature

Update UpdateCacheMiddleware to mark a response as cached

Reported by: Tim Schilling Owned by: Tyler Russin
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 (6)

comment:1 by Jacob Walls, 2 months ago

Triage Stage: Unreviewed → Accepted
Type: Uncategorized → New feature

Great idea!

comment:2 by Tyler Russin, 8 weeks ago

Owner: changed from Django Sprints to Tyler Russin

comment:3 by Tyler Russin, 8 weeks ago

Taking as part of Django sprints

comment:4 by Prakhar Goyal, 3 weeks ago

Owner: changed from Tyler Russin to Prakhar Goyal

comment:5 by Tim Schilling, 3 weeks ago

Owner: changed from Prakhar Goyal to Tyler Russin

@PrakharGoyal28 this is still within the typical window to allow Tyler to continue to work on this. Please respect our contributing guidelines.

comment:6 by Tyler Russin, 9 days ago

Thank you Tim for catching this. Yes, I am still very much so working on this ticket.

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