chibisov / drf-extensions

DRF-extensions is a collection of custom extensions for Django REST Framework
http://chibisov.github.io/drf-extensions/docs
MIT License
1.47k stars 208 forks source link

CacheResponseMixin doesn't work with custom list and response methods #159

Open Soviut opened 8 years ago

Soviut commented 8 years ago

I have a viewset with custom list() and retrieve() methods. I can put @cache_response() decorators on the methods and it successfully gets and sets to the cache. However, if I try to use CacheResponseMixin nothing happens.

The following caches.

class SeriesViewSet(viewsets.ReadOnlyModelViewSet):
    serializer_class = SeriesSerializer

    def get_queryset(self):
        series_type = EntityType.objects.get(name='series')
        return Container.objects.filter(type=series_type)

    @cache_response()
    def list(self, request):
        series = self.get_queryset()
        serializer = SeriesSerializer(series, many=True)
        return Response(serializer.data)

    @cache_response()
    def retrieve(self, request, pk=None):
        name = pk
        series = self.get_queryset()
        show = series.get(data__title=name)
        serializer = SeriesSerializer(show)
        return Response(serializer.data)

The following does not cache.

class SeriesViewSet(CacheResponseMixin, viewsets.ReadOnlyModelViewSet):
    serializer_class = SeriesSerializer

    def get_queryset(self):
        series_type = EntityType.objects.get(name='series')
        return Container.objects.filter(type=series_type)

    def list(self, request):
        series = self.get_queryset()
        serializer = SeriesSerializer(series, many=True)
        return Response(serializer.data)

    def retrieve(self, request, pk=None):
        name = pk
        series = self.get_queryset()
        show = series.get(data__title=name)
        serializer = SeriesSerializer(show)
        return Response(serializer.data)
grudelsud commented 7 years ago

@Soviut this seems a very old thread, but wondering if you checked that cache layer was working when using query strings? either using mixin or decorator, doesn't seem to work for a list response for me

auvipy commented 5 years ago

I want to know the current situation of this