cache_page with Class Based Views

前端 未结 8 1969
孤独总比滥情好
孤独总比滥情好 2020-12-14 06:23

I\'m trying to do cache_page with class based views (TemplateView) and i\'m not able to. I followed instructions here:

Django--URL Caching Failing for Class Based Vi

8条回答
  •  长情又很酷
    2020-12-14 07:15

    I didn't found a good cache solution for class based views and created my own: https://gist.github.com/svetlyak40wt/11126018

    It is a mixin for a class. Add it before the main base class and implement method get_cache_params like that:

    def get_cache_params(self, *args, **kwargs):
       return ('some-prefix-{username}'.format(
           username=self.request.user.username),
                3600)
    

提交回复
热议问题