Django 的模板标签“缓存”不在模板中缓存查询集

发布于 2024-10-03 13:44:40 字数 377 浏览 0 评论 0原文

我使用这样的缓存标签:

{% cache 1200 special %}
<div id="recommended-topics" class="ui-ce ui-ce-simple">
   {{aticle_list}}   
</div>
{% endcache %}

我发现在 memcache 中有一个名为 template.cache.special.d41d8cd98f00b204e9800998ecf8427e 的键。

但是,我仍然发现 django 执行查询来获取 article_list

为什么这不起作用?

I use cache tag like this :

{% cache 1200 special %}
<div id="recommended-topics" class="ui-ce ui-ce-simple">
   {{aticle_list}}   
</div>
{% endcache %}

I found that there is a key named template.cache.special.d41d8cd98f00b204e9800998ecf8427e in memcache.

however, I still find django execute the query to get the article_list

why this doesn't work??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知足的幸福 2024-10-10 13:44:40

我要检查的第一个地方是加载该模板的视图。您是否在视图中执行查询来填充article_list

如果是这样,那么您的模板缓存可能正在工作,但您仍在访问数据库以生成未使用的查询集。

如果是这种情况,最简单的解决方案是查看设置 每个视图缓存

First place I would check is the view which loads that template. Are you doing a query in the view to populate article_list?

If so, then your template cache may be working but you're still hitting the database to generate a queryset that's not being used.

If that's the case, the simplest solution would be to look at setting up per-view caches.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文