django中的查询,在写好查询条件之后,在不调用变量的时候,sql是不会执行的,只有在调用变量的时候,才回去执行,
在一次查询之后,会把变量放进内存,下次再使用这个变量的时候就会使用内存汇总的值。
可以看到,两次时间相差很大。
在python manage.py shell中进行查询,有种例外
taskHistories3 = TaskHistory.objects.only(‘createTime‘, ‘result_0‘).order_by(‘-createTime‘)[:5]
这种是没有缓存的,
又缓存的是这种的
因为:
Simply printing the queryset will not populate the cache. This is because the call to repr() only returns a slice of the entire queryset.
简单地打印queryset将不会填充缓存。这是因为对repr__()的调用只返回整个queryset的一部分。
原文:https://www.cnblogs.com/0916m/p/11848094.html