简体   繁体   中英

django: What's the up-to-date way to flush the queryset results cache?

In the current (2.0) version of Django, what today is the best way to force Django to ignore any queryset result caches that it may be harboring and to re-retrieve information from the database?

https://docs.djangoproject.com/en/dev/topics/db/queries/#caching-and-querysets ... explicitly talks about the cache, but doesn't actually say how to force it to be emptied.

I'd prefer to do this the "official" way. Surely there must be one.

Not sure if I missed something, but ignoring the cache means to fetch the data again. According to the doc page you linked

In a newly created QuerySet, the cache is empty.

So, instead of the example

queryset = Entry.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.

do

queryset = Entry.objects.all()
print([p.headline for p in queryset]) # Evaluate the query set.
queryset = Entry.objects.all()
print([p.pub_date for p in queryset]) # Evaluate the query set again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM