13

I'm just startimg to work with django and DRF, and I got a problem, that looks like DRF cache responses. I mean - I can change object, create new, or delete it - and DRF shows in response, that nothing has changed. For example, I create an object, but modelViewSet still return data where the newly created object is not present. But if I directly request the object - it shows 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, but not with DRF views.

Here is one of the serializers/modelViewSets that I'm using. It as simple as possible. And also - I'm not using django cache backends. At least - I don#t 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
3
  • 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? Commented Sep 21, 2015 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? Commented Sep 21, 2015 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? Commented Sep 21, 2015 at 13:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, shame on me. Thank you, I just need to use WorkOperation.objects.all() insted of return self.queryset. My inattention.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.