Opened 5 years ago

Closed 4 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 Carlton Gibson, 5 years ago

Triage Stage: UnreviewedAccepted

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.)

Last edited 5 years ago by Carlton Gibson (previous) (diff)

comment:2 by Danny Flack, 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 Carlton Gibson, 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 Danny Flack, 5 years ago

comment:5 by Flavio Curella, 5 years ago

Owner: changed from nobody to Flavio Curella
Status: newassigned

comment:6 by Flavio Curella, 5 years ago

Has patch: set

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In d08d4f4:

Fixed #30765 -- Made cache_page decorator take precedence over max-age Cache-Control directive.

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