Doadc
Doadc

Reputation: 145

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).

Upvotes: 1

Views: 2938

Answers (2)

Stefan_EOX
Stefan_EOX

Reputation: 1531

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.

Upvotes: 1

jamjar
jamjar

Reputation: 635

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.

Upvotes: 1

Related Questions