'Remove or expire cache from Django queryset
I have a Django project that have a large amount of transactions. Much queries. When using Django querysets they get cached, if I have understood it correctly.
I need to remove this cache, but have not found any information regarding it. My users would like to get the latest objects as fast as possible (60 seconds would work at least).
Solution 1:[1]
According to the Django docs:
In a newly created QuerySet, the cache is empty.
Thus, just begin using a new Queryset when you want to break the cache.
Solution 2:[2]
According to Django docs you can call .all()
on the QuerySet
:
When a QuerySet is evaluated, it typically caches its results. If the data in the database might have changed since a QuerySet was evaluated, you can get updated results for the same query by calling all() on a previously evaluated QuerySet.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jamjar |
Solution 2 | Stefan_EOX |