Opened 17 years ago
Closed 14 years ago
#6988 closed (wontfix)
Inconsistent CACHE_MIDDLEWARE_SECONDS = 0 meaning across cache backends
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Cache system) | Version: | dev |
Severity: | Keywords: | CacheMiddleware memcached CACHE_MIDDLEWARE_SECONDS | |
Cc: | eric@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
According to http://www.djangoproject.com/documentation/cache/#the-per-site-cache, settings.CACHE_MIDDLEWARE_SECONDS is "The number of seconds each page should be cached."
However, memcached takes a 0 second timeout to mean "cache forever" instead of "do not cache".
This patch enforces the Django meaning in django.core.cache.backends.memcached
Attachments (3)
Change History (11)
by , 17 years ago
Attachment: | django-memcached.patch added |
---|
by , 17 years ago
Attachment: | django-memcached.2.patch added |
---|
comment:1 by , 17 years ago
comment:2 by , 17 years ago
I guess I don't understand why someone would call cache.add()
or cache.set()
with something that's not meant to be cached...
comment:3 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
It is very common for 0 to mean "infinity" for those kind of settings. If you want to submit a patch to django's documentation to make that explicit, feel free to do so. If you want to disable caching in the settings then change the engine to dummy.
comment:4 by , 17 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
cache.add() and cache.set() with a timeout of 0 is used when CacheMiddleware is given a 0 second timeout.
You would want it in this case:
from django.conf import settings from django.views.decorators.cache import cache_page settings.CACHE_MIDDLEWARE_SECONDS = 300 # Obviously, this is done in settings.py @cache_page(0) def never_cache_this(request): ...
This works with all CACHE_BACKENDs other than memcached. This means that the semantics are different if you choose locmem:// instead of memcached://.../ which is not something that should be solved by documentation.
If 0 seconds means "cache forever", then I would be happy to prepare a patch to cause the other cache backends to behave the same way. But I believe that a 0 second timeout is valuable, because of CacheMiddleware's interface.
by , 17 years ago
Attachment: | django-memcached.3.patch added |
---|
memcached.py has the same semantics as other django.core.cache.backends
comment:5 by , 17 years ago
Cc: | added |
---|
comment:6 by , 17 years ago
Summary: | Memcached caches forever when CACHE_MIDDLEWARE_SECONDS = 0 → Inconsistent CACHE_MIDDLEWARE_SECONDS = 0 meaning across cache backends |
---|---|
Triage Stage: | Unreviewed → Accepted |
I understand that the issue is not that "0" means infinity, but that 0 means different things depending on the backend you use.
So either 0 means infinity to all, or means "do not cache".
comment:7 by , 14 years ago
Eligible to be closed due to recent changes/tests no longer requiring 0 as a insta-invaliation. May be worth noting in the documentation the difference, but a fair warning of YMMV should be enough.
comment:8 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
And closing to reflect the above.
The second patch is far more correct.