[Django] #32841: Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly

23 views
Skip to first unread message

Django

unread,
Jun 11, 2021, 2:51:26 PM6/11/21
to django-...@googlegroups.com
#32841: Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly
-----------------------------------------------+------------------------
Reporter: Iuri de Silvio | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+------------------------
The `cache_page` decorator don't use the setting because it always pass
`key_prefix=None` and `CacheMiddleware` consider it a valid config, so it
overrides the default one.

https://github.com/django/django/blob/854e9b066850b9b4eb1171966e996322b2c16d27/django/views/decorators/cache.py#L24
https://github.com/django/django/blob/ca9872905559026af82000e46cde6f7dedc897b6/django/middleware/cache.py#L175

I discovered the issue because I was moving from Django 3.1 to Django 3.2
and a 3.1 `HttpResponse` is not compatible with 3.2 `HttpResponse` (which
I think is ok, maybe could be better documented), so I have to clean the
cache changing my key prefix with the `CACHE_MIDDLEWARE_KEY_PREFIX`.

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

Django

unread,
Jun 11, 2021, 2:58:05 PM6/11/21
to django-...@googlegroups.com
#32841: Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
| Silvio
Type: Bug | Status: assigned

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

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Iuri de Silvio):

* owner: nobody => Iuri de Silvio
* status: new => assigned


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

Django

unread,
Jun 11, 2021, 2:59:35 PM6/11/21
to django-...@googlegroups.com
#32841: Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
| Silvio
Type: Bug | Status: assigned
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Iuri de Silvio):

* has_patch: 0 => 1


Comment:

I created a patch. Did some comments to it because I'm not totally happy
with the result, but it works.

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

Django

unread,
Jun 15, 2021, 3:46:18 AM6/15/21
to django-...@googlegroups.com
#32841: Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
| Silvio
Type: Bug | Status: closed

Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

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

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


Comment:

Hi.

`CACHE_MIDDLEWARE_KEY_PREFIX` is for
[https://docs.djangoproject.com/en/3.2/topics/cache/#the-per-site-cache
per-site caching] not for `cache_page`, which allows you to set an
additional prefix but is not intended to use the site-level settings.

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

Django

unread,
Jun 15, 2021, 4:41:51 AM6/15/21
to django-...@googlegroups.com
#32841: Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
| Silvio
Type: Bug | Status: closed
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Iuri de Silvio):

I misread the docs, expected it to work with `cache_page`. Unfortunately,
Django don't have an easy way for cleaning only `cache_page` cache, I'll
make a cache page wrapper on my side. Thanks!

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

Django

unread,
Jun 15, 2021, 5:20:39 AM6/15/21
to django-...@googlegroups.com
#32841: Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
| Silvio
Type: Bug | Status: closed
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

No problem. See #5815 for a suggestion to add easier invalidation here.
It's just looking for a hero to pick it up. 😉

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

Reply all
Reply to author
Forward
0 new messages