[Django] #32212: Vary header changed by SessionMiddleware

10 views
Skip to first unread message

Django

unread,
Nov 20, 2020, 3:19:29 AM11/20/20
to django-...@googlegroups.com
#32212: Vary header changed by SessionMiddleware
-------------------------------------+-------------------------------------
Reporter: y p | Owner: nobody
Type: | Status: new
Uncategorized |
Component: | Version: 2.2
Uncategorized | Keywords: cache Vary
Severity: Normal | SessionMiddleware
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
To specify the cache mode, i use the view decorator like this:
{{{
@vary_on_headers('Accept', 'Accept-Language', 'Origin', 'User-Agent')
@cache_control(public=True, max_age=3600)
}}}
But after tracing, I found that SessionMiddleware modified the Vary Header
and added a Cookie, as follows:
{{{
if accessed:
patch_vary_headers(response, ('Cookie',))
}}}
Causes cache invalidation after user login again.
I have specified the cache as public, in which case the cache scheme
should have nothing to do with cookies.

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

Django

unread,
Nov 20, 2020, 3:22:31 AM11/20/20
to django-...@googlegroups.com
#32212: Vary header changed by SessionMiddleware
-------------------------------------+-------------------------------------
Reporter: y p | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Resolution:
Keywords: cache Vary | Triage Stage:
SessionMiddleware | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by y p:

Old description:

> To specify the cache mode, i use the view decorator like this:
> {{{
> @vary_on_headers('Accept', 'Accept-Language', 'Origin', 'User-Agent')
> @cache_control(public=True, max_age=3600)
> }}}
> But after tracing, I found that SessionMiddleware modified the Vary
> Header and added a Cookie, as follows:
> {{{
> if accessed:
> patch_vary_headers(response, ('Cookie',))
> }}}
> Causes cache invalidation after user login again.
> I have specified the cache as public, in which case the cache scheme
> should have nothing to do with cookies.

New description:

To specify the cache mode, i use the view decorator like this:
{{{

@vary_on_headers('Accept', 'Accept-Language', 'Origin')


@cache_control(public=True, max_age=3600)
}}}
But after tracing, I found that SessionMiddleware modified the Vary Header
and added a Cookie, as follows:
{{{
if accessed:
patch_vary_headers(response, ('Cookie',))
}}}
Causes cache invalidation after user login again.
I have specified the cache as public, in which case the cache scheme
should have nothing to do with cookies.

--

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

Django

unread,
Nov 24, 2020, 4:09:50 AM11/24/20
to django-...@googlegroups.com
#32212: Vary header changed by SessionMiddleware
-------------------------------------+-------------------------------------
Reporter: y p | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 2.2
Severity: Normal | Resolution: wontfix

Keywords: cache Vary | Triage Stage:
SessionMiddleware | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* status: new => closed
* resolution: => wontfix


Comment:

I'm afraid this is as-designed. It's just how session middleware works.
See #3586 for the change implementing the current behaviour.

If you need hard caching here then serve the "static" pages from a
separate app, without Session middleware, and use JavaScript to load the
user-specific sections.

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

Reply all
Reply to author
Forward
0 new messages