Django Rest Framework Cache Headers

I am trying to cache some of my DRF api calls in a CDN. I need the following Cache-Control headers: public, max-age = XXXX

It's pretty simple when you use the traditional django template, you just add the @cache_page () @cache_control (public = True) decorators, but for DRF I can not find anything like it. There are quite a lot of mem caches, but I really would like the CDN to completely transfer the load from my server, I would like to cache the resulting request.

I also use modelViewSets if that matters for everything:

class EventViewSet(viewsets.ModelViewSet):

    serializer_class = EventViewSet
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
    pagination_class = pagination.LimitOffsetPagination
    filter_backends = (filters.DjangoFilterBackend, filters.SearchFilter,)
    filter_class = EventFilter
    search_fields = ('name','city','state')

    def get_queryset(self):
+4
source share
1 answer

: Django Django Rest Framework. nginx conf.

0

Source: https://habr.com/ru/post/1659271/


All Articles