[Answer]-Django: How to dynamically set view cache timeout value?

1👍

You can do it manually in your view class. Something like:

class MyView(View):
    def get(self, *args, **kwargs):
        response_data = cache.get('some_key')
        if response_data is None:
            response = super(MyView, self).get(*args, **kwargs)
            cache.set('some_key', response.content, 300)
        else:
            response = HttpResponse(response_data)
        return response
👤ilvar

Leave a comment