我正在尝试在每个视图缓存上使用带有django的memcache。 问题是缓存只有在我刷新页面时才会被设置,单击相同的链接不会设置缓存。(即如果我在调度和重新加载页面上设置cache_view,我看到查询数量下降到3-4查询否则点击相同的链接,没有设置缓存,即使再次点击相同的网址,我也得到相同数量的查询)
以下是我的观点:
class ProductCategoryView(TemplateView):
"""
Browse products in a given category
"""
context_object_name = "products"
template_name = 'catalogue/category.html'
enforce_paths = True
@method_decorator(cache_page(30))
def dispatch(self, request, *args, **kwargs):
return super(ProductCategoryView, self).dispatch(request, *args, **kwargs)
我的缓存设置为:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
我的中间件是:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'oscar.apps.basket.middleware.BasketMiddleware',
'django.middleware.transaction.TransactionMiddleware',
)
感谢。