Opened 10 years ago

Closed 10 years ago

#9221 closed (fixed)

Cache Middleware wrong behavior.

Reported by: Wonlay Owned by: nobody
Component: Core (Cache system) Version: master
Severity: Keywords: CACHE_MIDDLEWARE_SECONDS, zero
Cc: wonlay@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When the CACHE_MIDDLEWARE_SECONDS setting is set to zero,

UpdateCacheMiddleware will set a cache item which timeout is 300.

# This line pass timeout=0.
cache.set(cache_key, response, timeout)

# But in django/core/cache/backends/
self._cache.set(smart_str(key), value, timeout or self.default_timeout)
# will set the timeout to self.default_timeout, which is 300.

Actually, if CACHE_MIDDLEWARE_SECONDS=0 there is no need to call cache.set(...
Only patch the header max_age to 0 will be OK.

And my patch attached.

Attachments (1)

cache_timeout_0_bug.patch (715 bytes) - added by Wonlay 10 years ago.

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by Wonlay

Attachment: cache_timeout_0_bug.patch added

comment:1 Changed 10 years ago by Wonlay

Cc: wonlay@… added

comment:2 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [9098]) Fixed #9221 -- Small optimisation to caching middleware handling.

In the slightly unusual case that CACHE_MIDDLEWARE_SECONDS is set to 0, don't
bother storing a copy in the local cache.

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