diff options
| author | mengxun <mengxun1122@163.com> | 2025-08-19 15:40:37 +0800 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-08-21 16:48:36 +0200 |
| commit | ed7c1a56400d64f109f30df3ce697984cdad7c75 (patch) | |
| tree | 7758769f8c2f2167a4ab499ded5973ce63314ed3 /django | |
| parent | d3cf24e9b415b41f570c9f426b2cd113b5fdb4de (diff) | |
Fixed #36560 -- Prevented UpdateCacheMiddleware from caching responses with Cache-Control 'no-cache' or 'no-store'.
Diffstat (limited to 'django')
| -rw-r--r-- | django/middleware/cache.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/django/middleware/cache.py b/django/middleware/cache.py index 10fff365af..8c42a52b4a 100644 --- a/django/middleware/cache.py +++ b/django/middleware/cache.py @@ -100,8 +100,17 @@ class UpdateCacheMiddleware(MiddlewareMixin): ): return response - # Don't cache a response with 'Cache-Control: private' - if "private" in response.get("Cache-Control", ()): + # Don't cache responses when the Cache-Control header is set to + # private, no-cache, or no-store. + cache_control = response.get("Cache-Control", ()) + if any( + directive in cache_control + for directive in ( + "private", + "no-cache", + "no-store", + ) + ): return response # Page timeout takes precedence over the "max-age" and the default |
