How to disable Django query cache?

后端 未结 5 977
既然无缘
既然无缘 2020-11-27 15:32

In my Django application, I repeatedly run the same query on my database (e.g. every 10 seconds). I then create an MD5 sum over the queryset I receive and compare that to th

5条回答
  •  情话喂你
    2020-11-27 16:16

    I met this problem on django version 1.8. There is not direct way to do it, but there are some ways to make the queryset re-evaluated and executed by accessing db instead of cache. I found it in Django Queryset Documentation

    I used one of them to handle my problem. It is exists() function of querysets. len() and repr() can also be used. They worked for me too.

    Example

    queryset = ModelClass.objects.filter(....)
    queryset.exists()
    
    #or len(queryset)
    #or repr(queryset)
    
    #Now queryset is re-evaluated. 
    

提交回复
热议问题