python - How to cache Django Rest Framework API calls? - Stack Overflow

PHOTO EMBED

Fri Nov 18 2022 08:39:03 GMT+0000 (Coordinated Universal Time)

Saved by @jacopo #python

from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page

class ProductListAPIView(generics.ListAPIView):
    serializer_class = ProductSerializer

    @method_decorator(cache_page(60))
    def dispatch(self, *args, **kwargs):
        return super(ProductListAPIView, self).dispatch(*args, **kwargs)
content_copyCOPY

https://stackoverflow.com/questions/38320008/how-to-cache-django-rest-framework-api-calls