Opened 8 years ago

Closed 8 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: UI/UX:


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 8 years ago.

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by Wonlay

comment:1 Changed 8 years ago by Wonlay

  • Cc wonlay@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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