django Cache only gets set on page reload

江枫思渺然 提交于 2019-12-25 07:46:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!