一些缓存问题

时间:2011-02-27 23:08:22

标签: django caching django-cache

  1. 我想知道是否可以删除模板缓存中生成的缓存内容。我想从我的视图中删除它。我的模板{% cache 500 cache_name sites.number %} 是否可以删除视图中的所有“cache_name”缓存内容,例如,当进行某些操作时?

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

  3.   

    异常类型: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
    

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

  

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