【问题标题】:Some cache problems一些缓存问题
【发布时间】:2011-07-05 10:28:00
【问题描述】:
  1. 我想知道是否可以删除在模板缓存中制作的缓存内容。我想从我的视图中删除它。我的模板中有{% cache 500 cache_name sites.number %} 是否可以删除视图中的所有“cache_name”缓存内容,例如在执行某些操作时?

  2. 我想使用per-vie cache。我做了所有描述的事情,但是当我打电话时:@cache_page(3600, cache="cache_name") 我得到错误:

异常类型:ValueError异常 值:需要超过 1 个值 解压

(以下是回溯)

我想要实现的是缓存我的所有模板块或视图,并有可能在执行某些操作时删除与其相关的所有缓存。包含分页

追溯

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

【问题讨论】:

    标签: django caching django-cache


    【解决方案1】:

    您使用的是哪个版本的 Django?参数“cache”仅在开发版本中可用。如果您使用的是 Django 1.2,则只能使用“key_prefix”。

    【讨论】:

    • 正如您在我的第一篇跟踪中看到的那样:Django 版本:1.3 beta 1 SVN-15661
    【解决方案2】:

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

    缓存中间件缓存每一页 没有 GET 或 POST 参数。

    【讨论】:

      猜你喜欢
      • 2011-06-26
      • 1970-01-01
      • 2011-07-21
      • 2014-06-13
      • 2011-07-29
      • 2013-06-06
      • 2011-10-22
      • 2011-08-12
      相关资源
      最近更新 更多