django - django:刷新查询集结果缓存的最新方法是什么?
问题描述
在当前(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.
推荐阅读
- javascript - 在不同 X 轴上的 Highcharts 中显示列(并排)
- java - Mybatis ORA-00911: 无效字符
- python - 如何以编程方式确保函数包含 return 语句?
- python - 如何将雪花主键读入python
- flutter - 在 Flutter 中使用 Android Intent 打开 PDF
- python - Python 请求库限制 api 调用
- reactjs - laravel react webpack 用 dist 文件制作了许多额外的 .js
- r - (AD) 使用 shinywidgets 从 pickerInput 中删除“全选”操作按钮
- visual-studio - 如何在 VIsual Studio 2019 Windows 10 上安装 Visual Studio 2010 (v100) 平台工具集?
- angular - 如何在 Angular 中始终如一地获取延迟加载模块的根路由?