#16334 closed Cleanup/optimization (fixed)
cache_page decorator does not accept "cache" keyword argument
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Docs for cache_page: https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs#django.views.decorators.cache.cache_page
They point out a cache
keyword argument one can use:
cache_page can also take an optional keyword argument, cache, which directs the decorator to use a specific cache alias when caching view results. By default, the default alias will be used, but you can specify any cache alias you want
I assume this means I can specify the cache_key to use. So, like the docs state I try this out:
@cache_page(60 * 15, cache="special_cache")
def my_view(request):
....
As soon as I do this I get a ValueError with the following exception & traceback:
"need more than 1 value to unpack"
Request Method: GET Request URL: ... Django Version: 1.3 Python Version: 2.6.1 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.flatpages', 'django.contrib.humanize', 'django.contrib.messages', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.markup', 'django.contrib.comments', ... ... ] Traceback: File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response 101. request.path_info) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve 252. sub_match = pattern.resolve(new_path) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve 252. sub_match = pattern.resolve(new_path) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve 158. return ResolverMatch(self.callback, args, kwargs, self.name) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_callback 164. self._callback = get_callable(self._callback_str) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/utils/functional.py" in wrapper 124. result = func(*args) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/urlresolvers.py" in get_callable 91. lookup_view = getattr(import_module(mod_name), func_name) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) File "/Users/bartekc/domains/www.mysite.com/mysite/about_us/careers/views.py" in <module> 23. @cache_page(60 * 60, cache="careers_special") File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/views/decorators/cache.py" in cache_page 58. return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], cache_alias=cache_alias, key_prefix=key_prefix) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/utils/decorators.py" in _make_decorator 81. middleware = middleware_class(*m_args, **m_kwargs) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/middleware/cache.py" in __init__ 204. self.cache = get_cache(self.cache_alias, **cache_kwargs) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/cache/__init__.py" in get_cache 173. backend, location, params = parse_backend_conf(backend, **kwargs) File "/Users/bartekc/.virtualenvs/www.mysite.com/lib/python2.6/site-packages/django/core/cache/__init__.py" in parse_backend_conf 131. mod_path, cls_name = backend.rsplit('.', 1) Exception Type: ValueError at ... Exception Value: need more than 1 value to unpack
Change History (6)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Keryn, ah yes .. you're right. This makes a lot more sense now. I had a feeling it wasn't meant for what I thought it was for, but the documentation was confusing in that aspect.
comment:3 by , 14 years ago
Component: | Core (Cache system) → Documentation |
---|---|
Type: | Bug → Cleanup/optimization |
comment:4 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Reading the docs and the traceback, I believe a misunderstanding is at work. The cache argument is, I think, a hint for which cache backend (or 'alias' in the new
CACHES
dictionary) to utilise; this seems borne out by the traceback, but I do think the documentation wording could be clarified.