[Django] #30765: cache_control() "max_age" overrides cache_page() "timeout"

15 views
Skip to first unread message

Django

unread,
Sep 5, 2019, 2:25:08 PM9/5/19
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny | Owner: nobody
Flack |
Type: Bug | Status: new
Component: Core | Version: 2.2
(Cache system) | Keywords: cache_control
Severity: Normal | cache_page UpdateCacheMiddleware
Triage Stage: | CacheMiddleware
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30765>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 11, 2019, 6:22:51 AM9/11/19
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny Flack | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage: Accepted
cache_page UpdateCacheMiddleware |
CacheMiddleware |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Unreviewed => Accepted


Comment:

OK, yes, this seems legitimate.

Current behaviour was deliberately introduced in #5813
(f2f6e70b08b1142055e33e75f58cfe7fbb5d868f).

(Looking at
[https://code.djangoproject.com/query?status=!closed&component=Core+(Cache+system)
tickets for Core+(Cache+system)] there are a few on similar, though not
exactly, topics.)

--
Ticket URL: <https://code.djangoproject.com/ticket/30765#comment:1>

Django

unread,
Sep 11, 2019, 9:32:09 AM9/11/19
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny Flack | Owner: nobody
Type: Bug | Status: new

Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage: Accepted
cache_page UpdateCacheMiddleware |
CacheMiddleware |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Danny Flack):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30765#comment:2>

Django

unread,
Sep 12, 2019, 4:16:06 AM9/12/19
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny Flack | Owner: nobody
Type: Bug | Status: new

Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage: Accepted
cache_page UpdateCacheMiddleware |
CacheMiddleware |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

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!

--
Ticket URL: <https://code.djangoproject.com/ticket/30765#comment:3>

Django

unread,
Sep 12, 2019, 8:30:53 PM9/12/19
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny Flack | Owner: nobody
Type: Bug | Status: new

Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage: Accepted
cache_page UpdateCacheMiddleware |
CacheMiddleware |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Danny Flack):

Thanks. I posted a new topic on that list.
https://groups.google.com/forum/#!topic/django-developers/BwTZFMpqd6U

--
Ticket URL: <https://code.djangoproject.com/ticket/30765#comment:4>

Django

unread,
Sep 26, 2019, 2:00:11 PM9/26/19
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny Flack | Owner: Flavio
| Curella
Type: Bug | Status: assigned

Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage: Accepted
cache_page UpdateCacheMiddleware |
CacheMiddleware |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Flavio Curella):

* owner: nobody => Flavio Curella
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30765#comment:5>

Django

unread,
Sep 26, 2019, 2:57:49 PM9/26/19
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny Flack | Owner: Flavio
| Curella
Type: Bug | Status: assigned
Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage: Accepted
cache_page UpdateCacheMiddleware |
CacheMiddleware |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Flavio Curella):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/11823 PR on github]

--
Ticket URL: <https://code.djangoproject.com/ticket/30765#comment:6>

Django

unread,
Jan 16, 2020, 8:31:58 AM1/16/20
to django-...@googlegroups.com
#30765: cache_control() "max_age" overrides cache_page() "timeout"
-------------------------------------+-------------------------------------
Reporter: Danny Flack | Owner: Flavio
| Curella
Type: Bug | Status: closed

Component: Core (Cache system) | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: cache_control | Triage Stage: Accepted
cache_page UpdateCacheMiddleware |
CacheMiddleware |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d08d4f464ab11cc226d4e197c0f43e26a7fd2961" d08d4f4]:
{{{
#!CommitTicketReference repository=""
revision="d08d4f464ab11cc226d4e197c0f43e26a7fd2961"
Fixed #30765 -- Made cache_page decorator take precedence over max-age
Cache-Control directive.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30765#comment:7>

Reply all
Reply to author
Forward
0 new messages