13

I'm just start working with django and DRF, and occure a problem, that is looks like DRF cache responses. I mean - I can change object, create new, or delete it - and DRF keep response, thats nothing is changed. For example, I create an object, but modelViewSet still return data where this object does not presented. But if I directly request it object - it show that it's created. And so with any another actions. I can't find topic about caching in DRF, and look like I have not any django chaching middlewares, so I have no idea what is going on. Only one thing that helps - restart server ( I'm using default dev-server).

One more thing - all data is ok when it's rendered by django views, not DRF views.

Here is one of the serializers/modelViewSets that I'm using. It simple as it possible. And also - I'm not using django cache backends. At least - I have not any in my settings.

class WorkOperationSerializer(serializers.ModelSerializer):
    class Meta:
        model = WorkOperation


class WorkOperationAPIView(viewsets.ModelViewSet):
    serializer_class = WorkOperationSerializer
    queryset = WorkOperation.objects.all()

    def get_queryset(self):
        return self.queryset
GeraldIstar
  • 368
  • 1
  • 4
  • 16
  • There is no such thing built into DRF, are you sure that caching appears on DRF side? Maybe there is something else in django that perform this cache or it's in your browser? – GwynBleidD Sep 21 '15 at 13:50
  • Well, looks that is not a browser - other people also see same results. And as I said - I have not any caching middleware. Django use middleware for caching, right? – GeraldIstar Sep 21 '15 at 13:52
  • Can you post view and serializer that are affected by that cache, also what cache backends are you using in django project? – GwynBleidD Sep 21 '15 at 13:53

1 Answers1

12

You can read here about django queryset caching. The best advice seems to be: re-run the .all() method to get fresh results. Using object.property may give you cached results.

allo
  • 3,955
  • 8
  • 40
  • 71
  • 3
    Ah, shame on me. Thank you, I just need to use `WorkOperation.objects.all()` insted of return `self.queryset`. My inattention. – GeraldIstar Sep 21 '15 at 14:26