queryset = Entry.objects.all()
print([p.headline for p in queryset]) # 当遍历一次时,会进行缓存
print([p.pub_date for p in queryset]) # 这次调用就使用了上面的缓存,较少数据库IO
queryset = Entry.objects.all()
print(queryset[5]) # 查询数据库,此时是切片,切片不会被缓存
print(queryset[5]) # 因为上面没有被缓存,所以这次是再次查询数据库
queryset = Entry.objects.all()
[entry for entry in queryset] # 查询数据库,因为遍历了,所以进行缓存
print(queryset[5]) # 使用缓存
print(queryset[5]) # 使用缓存