Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#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 Keryn Knight <keryn@…>, 14 years ago

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.

comment:2 by anonymous, 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 anonymous, 14 years ago

Component: Core (Cache system)Documentation
Type: BugCleanup/optimization

comment:4 by Łukasz Rekucki, 14 years ago

Triage Stage: UnreviewedAccepted

comment:5 by James Bennett, 13 years ago

Resolution: fixed
Status: newclosed

In [16815]:

Fixed #16334: Make it quite clear that cache_page's 'cache' argument refers to the name of a cache in the CACHES setting.

comment:6 by James Bennett, 13 years ago

In [16816]:

[1.3.X] Fixed #16334: Make it quite clear that cache_page's 'cache' argument refers to the name of a cache in the CACHES setting. Backport of [16815] from trunk.

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