Some cache problems

1.8k Views Asked by At
  1. I'm wondering if I can delete a cached content made in template cache. I want to delete it from my view. I have in my template {% cache 500 cache_name sites.number %} Is it possible to delete all "cache_name" cached content within the view, for example when some action is made?

  2. I want to use per-vie cache. I do all what is described, but when I call: @cache_page(3600, cache="cache_name") I get error:

Exception Type: ValueError Exception Value: need more than 1 value to unpack

(Below is the traceback)

What I want to achieve is to cache all my template block or view and have a possibility to delete all cache connected with it when some actions are made. Pagination is included

Traceback:

Environment:


Request Method: GET
Request URL: http://localhost:8000/portfolio/

Django Version: 1.3 beta 1 SVN-15661
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'apps.index']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "E:\Python\django\core\handlers\base.py" in get_response
  101.                             request.path_info)
File "E:\Python\django\core\urlresolvers.py" in resolve
  252.                     sub_match = pattern.resolve(new_path)
File "E:\Python\django\core\urlresolvers.py" in resolve
  252.                     sub_match = pattern.resolve(new_path)
File "E:\Python\django\core\urlresolvers.py" in resolve
  158.             return ResolverMatch(self.callback, args, kwargs, self.name)
File "E:\Python\django\core\urlresolvers.py" in _get_callback
  164.             self._callback = get_callable(self._callback_str)
File "E:\Python\django\utils\functional.py" in wrapper
  124.         result = func(*args)
File "E:\Python\django\core\urlresolvers.py" in get_callable
  91.                 lookup_view = getattr(import_module(mod_name), func_name)
File "E:\Python\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "E:\Python\apps\index\views.py" in <module>
  29. @cache_page(600, cache='my_cache')
File "E:\Python\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 "E:\Python\django\utils\decorators.py" in _make_decorator
  81.         middleware = middleware_class(*m_args, **m_kwargs)
File "E:\Python\django\middleware\cache.py" in __init__
  204.         self.cache = get_cache(self.cache_alias, **cache_kwargs)
File "E:\Python\django\core\cache\__init__.py" in get_cache
  173.             backend, location, params = parse_backend_conf(backend, **kwargs)
File "E:\Python\django\core\cache\__init__.py" in parse_backend_conf
  131.         mod_path, cls_name = backend.rsplit('.', 1)

Exception Type: ValueError at /portfolio/
Exception Value: need more than 1 value to unpack
2

There are 2 best solutions below

0
On

http://docs.djangoproject.com/en/1.2/topics/cache/

The cache middleware caches every page that doesn't have GET or POST parameters.

1
On

What version of Django are you using? The parameter "cache" is only available in the development version. If you're using Django 1.2, you can only use "key_prefix".