代码之家  ›  专栏  ›  技术社区  ›  Mike Robinson

django:刷新queryset结果缓存的最新方法是什么?

  •  0
  • Mike Robinson  · 技术社区  · 7 年前

    在 现在的 (2.0)版本的Django,什么 今天

    https://docs.djangoproject.com/en/dev/topics/db/queries/#caching-and-querysets ... 明确地谈论缓存,但实际上没有说明如何强制清空缓存。

    当然

    1 回复  |  直到 7 年前
        1
  •  0
  •   C14L    7 年前

    不确定是否遗漏了某些内容,但忽略缓存意味着再次获取数据。根据您链接的文档页面

    在新创建的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.