问题
I am trying my hands around using memcache with django on per-view cache. The trouble is cache only gets set if i refresh a page,clicking on same link does not sets the cache.(that is if i set cache_view on dispatch and reload page, i see the number of queries fall down to 3-4 queries otherwise on clicking the same link, cache is not set, and i get the same number of queries even after hitting the same url again and again)
Here is my views:
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)
My cache settings is:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
My middlewares are:
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',
)
Thanks.
来源:https://stackoverflow.com/questions/37799255/django-cache-only-gets-set-on-page-reload