![](/img/trans.png)
[英]A simple and up-to-date way to implement Facebook login in a Django app
[英]django: What's the up-to-date way to flush the queryset results cache?
在当前 (2.0)版本的Django中, 今天什么是强迫Django忽略它可能包含的任何查询集结果缓存并从数据库中重新获取信息的最佳方法?
https://docs.djangoproject.com/en/dev/topics/db/queries/#caching-and-querysets ...明确地讨论了缓存,但并未实际说明如何强制清空它。
我宁愿以“官方”方式进行此操作。 当然必须有一个。
不知道我是否错过了什么,但是忽略缓存意味着再次获取数据。 根据您链接的文档页面
在新创建的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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.