Django Rest Framework Cache Headers
@method_decorator
can be applied to the view class. When provided with a name
argument, it will wrap that named method in instances of that class. What you want is something along the lines of:
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_control
@method_decorator(cache_control(public=True, max_age=xxxx), name='dispatch')
class EventViewSet(viewsets.ModelViewSet):
...
Did you try:
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_control
class EventViewSet(viewsets.ModelViewSet):
@method_decorator(cache_control(private=False, max_age=xxxx)
def dispatch(self, request, *args, **kwargs):
return super(EventViewSet, self).dispatch(request, *args, **kwargs)