Opened 5 years ago
Closed 5 years ago
#30765 closed Bug (fixed)
cache_control() "max_age" overrides cache_page() "timeout"
Reported by: | Danny Flack | Owned by: | Flavio Curella |
---|---|---|---|
Component: | Core (Cache system) | Version: | 2.2 |
Severity: | Normal | Keywords: | cache_control cache_page UpdateCacheMiddleware CacheMiddleware |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you decorate a view with both cache_control(max_age=3600)
and cache_page(timeout=3600*24)
, the server side cache uses the max_age
value instead of the timeout
value.
The comments in UpdateCacheMiddleware.process_response()
indicate it's trying to set the timeout by first looking for the max-age
header before reverting to the default cache_timeout :
Try to get the timeout from the "max-age" section of the "Cache-
Control" header before reverting to using the default cache_timeout
length.
However, cache_page(timeout=3600*24)
is explicitly setting the cache_timeout
so that is what should be used.
In summary, if a user wants the client-side cache to be shorter-lived than the server-side cache, it is currently not possible using these two decorators.
Change History (7)
comment:1 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 5 years ago
I have an idea of how to solve this but I assume the core developers have a better understanding of why it was done this way in the first place, and what else it'll affect. Is it worth me submitting a patch? Please let me know how I can help.
comment:3 by , 5 years ago
Hi Danny.
Perhaps a post to the DevelopersMailingList, explaining as clearly as possible what's going on, and your idea, would be the best way to go.
That way, you're likely to get the feedback you need.
Thanks!
comment:4 by , 5 years ago
Thanks. I posted a new topic on that list. https://groups.google.com/forum/#!topic/django-developers/BwTZFMpqd6U
comment:5 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
OK, yes, this seems legitimate.
Current behaviour was deliberately introduced in #5813 (f2f6e70b08b1142055e33e75f58cfe7fbb5d868f).
(Looking at tickets for Core+(Cache+system) there are a few on similar topics, though not exactly so.)