Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32841 closed Bug (invalid)

Decorator cache_page don't use CACHE_MIDDLEWARE_KEY_PREFIX properly

Reported by: Iuri de Silvio Owned by: Iuri de Silvio
Component: Core (Cache system) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (5)

comment:1 by Iuri de Silvio, 3 years ago

Owner: changed from nobody to Iuri de Silvio
Status: newassigned

comment:2 by Iuri de Silvio, 3 years ago

Has patch: set

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

comment:3 by Carlton Gibson, 3 years ago

Resolution: invalid
Status: assignedclosed

Hi.

CACHE_MIDDLEWARE_KEY_PREFIX is for 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.

comment:4 by Iuri de Silvio, 3 years ago

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!

comment:5 by Carlton Gibson, 3 years ago

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

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