How to disable Django query cache?

后端 未结 5 971
既然无缘
既然无缘 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:00

    The link you provide to the Django Documentation implies that the following:

    >>> print [e.headline for e in Entry.objects.all()]
    >>> print [e.pub_date for e in Entry.objects.all()]
    

    creates two queries to the database, whilst:

    >>> queryset = Poll.objects.all()
    >>> print [p.headline for p in queryset] # Evaluate the query set.
    >>> print [p.pub_date for p in queryset] # Re-use the cache from the evaluation.
    

    uses the query cache, as you are accessing the same evaluation results.

提交回复
热议问题