In my view, I often use APIView's as_view()
to generate json.
I'd like to cache the response and tried the following but it won't work
def some_complex_view(self, request, *args, **kwargs):
pass
@method_decorator(cache_page(60, key_prefix='drf'))
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
Then, I call
def my_view(request, *args, **kwargs):
json_data = MyViewSet.as_view({'get': 'some_complex_view'})(request, format='json')
data = {
'my_data': json_data
}
return render(request, 'my_template.html', data)
It correctly caches when I request the view using browser, but it won't when using as_view()