在Django的 current (2.0)版本中,今天的 是强制Django忽略它可能包含的任何查询集结果缓存并重新执行的最佳方法。 -从数据库中检索信息?
https://docs.djangoproject.com/en/dev/topics/db/queries/#caching-and-querysets ...明确地谈论了缓存,但实际上没有说出如何强制清空缓存。
我宁愿以“官方”方式进行此操作。 当然必须有一个。
答案 0 :(得分:0)
不确定我是否错过了某些内容,但是忽略缓存意味着再次获取数据。根据您链接的文档页面
在新创建的QuerySet中,缓存为空。
因此,而不是示例
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.
做
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.