Django缓存和分页

时间:2014-03-05 11:23:46

标签: django caching pagination

我有一个分页视图(下面的SubmissionsLazyload),由于不需要的缓存,它没有按预期更新。

Views.py

class PublisherDetailViewCat(ListView):
    template_name = "recent_submi.html"
    paginate_by = 20

    def get_queryset(self, **kwargs):
        qset = CEntry.objects.filter(active=True)
        return qset


class SubmissionsLazyload(PublisherDetailViewCat):
    template_name = "snippets/submissions_lazy_load.html"

settings.py中的缓存设置

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'iso-cache'
    }
}
CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True
MIDDLEWARE_CLASSES = (
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'profiles.middleware.SocialAuthExceptionMiddleware',
)

下面是我如何解决当前的问题,有没有办法同时启用缓存和使用分页视图。?

from django.views.decorators.cache import never_cache


class SubmissionsLazyload(PublisherDetailViewCat):
    template_name = "snippets/submissions_lazy_load.html"
    @never_cache
    def dispatch(self, *args, **kwargs):
        return super(SubmissionsLazyload, self).dispatch(*args, **kwargs)

在python 2.6.5和2.7

中测试了Django版本1.4.1

0 个答案:

没有答案