Code

Opened 6 years ago

Closed 6 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:

Description

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/memcached.py:
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 6 years ago.

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by Wonlay

comment:1 Changed 6 years ago by Wonlay

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

comment:2 Changed 6 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.