Reputation: 2125
I don`t find infos on how caching of Django Rest Framework generic views is configured. Do I have to override the get message and add an own @method_decorator? This feels ungeneric to me.
class BlogTags(generics.ListAPIView):
queryset = CustomContentBlogTag.objects.all()
serializer_class = CustomContentBlogTagSerializer
permission_classes = [AllowAny]
@method_decorator(cache_page(60 * 60 * 24))
def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)
Docs I found:
Caching: https://www.django-rest-framework.org/api-guide/caching/
Generic views: https://www.django-rest-framework.org/api-guide/generic-views/
In the generic views docs, there is a sentence, that the queryset is cached somehow. But what, if I want the whole view to be cached?
Upvotes: 0
Views: 465
Reputation: 845
You can use the name
parameter on method_decorator
and decorate a class. In fact when you use it on a class, the name
is required.
Example:
@method_decorator(cache_page(60 * 5), name="list")
class MyView(mixins.ListModelMixin, GenericViewSet):
...
Upvotes: 1