Django缓存错误..即使禁用了缓存 [英] Django caching bug .. even if caching is disabled

查看:44
本文介绍了Django缓存错误..即使禁用了缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django网站,其中发生了一个奇怪的错误.

I have a Django site where a strange bug is occurring.

他们可以在网站上添加出版物",这与使用不同名称的博客帖子基本相同.

On the site they can add "publications", which is basically the same thing as a blog post under a different name.

当他们修改现有帖子时,事情变得很奇怪.他们首先在管理员中对其进行了修改,当他们进入网站时,所做的更改是不可见的.就像是旧版本被缓存一样.

Things gets weird when they modify an existing post. They first modify it in the admin and when they go on the site, the change isn't visible. Like if the old version was cached.

实际上,一开始我就很确定这是一个浏览器缓存错误.但是经过一番尝试,事情变得有些奇怪了.

In fact, at the beginning I was pretty sure it was a browser caching bug. But after some trials, things got a little weirder.

我发现清除浏览器缓存或使用其他浏览器并不能解决问题,但有趣的是,刷新后它会在旧版本和修改后的版本之间切换.

I found out that clearing browser cache or using a different browser does not solve the problem, but rather interestingly it toggles between the old version and the modified version upon refresh.

因此,如果帖子的正文是"Hello World",并且将其修改为"Goodbye残酷的世界",然后转到该网站并刷新页面多次,则我会看到"Hello World",然后是"Goodbye".残酷的世界",然后是"Hello World"等等.无论我坚持多久.

So if the body of the post was "Hello World" and I modify it to be "Goodbye cruel world" and then go to the site and refresh the page multiple times, I would see "Hello World", then "Goodbye cruel world", then "Hello World" and so on.. no matter how long I keep doing it.

但是它并没有就此停止..大约24小时后,一切恢复原状并正常工作.不再排列,该网站将继续使用新版本...

But it doesn't stop there .. after about 24h everything falls back into place and work normally. No permutation anymore, the site sticks to the new version...

我几乎无言以对,因为我使用同一台服务器构建了50多个其他Django站点,而且以前从未遇到过此问题.

I'm pretty much speechless because I built well over 50 other Django sites using the same server and I never had this problem before.

我正在将最新的django(1.3)与MySQL数据库一起使用,并且未启用缓存..

I'm using the latest django (1.3) with a MySQL DB and caching is not enabled..

有什么想法吗?

编辑:正常重启Apache可以解决问题..但是在每次更新后重启apache并不是最大的事情.

Edit: A graceful restart of Apache solve the problem .. but restarting apache after each update isn't the greatest thing..

更新:我刚刚重新设置了我的开发环境,发现该错误对于开发服务器更为严重.无论我刷新或清除缓存的频率如何,直到我终止/重新启动开发服务器之前,修改后的竞争条件才会显示.

Update: I've just re-setuped my dev environement and I found out the bug is far more acute with the dev server. The modified contend won't show up until I kill/restart the dev server, no matter how often I refresh or clear my cache..

推荐答案

The problem is explicitly addressed in the generic views documentation. The querysets in your extra_context dictionary are evaluated once, when the urlconf is first processed, and each time after that they will continue to use the same values. That's why they only change when you reset Apache or the dev server.

如链接页面上所述,解决方案是使用可返回查询集的可调用对象,而不是在字典本身中指定查询集.

The solution, as described on the linked page, is to use callables which return the querysets, rather than specifying the querysets in the dictionary itself.

这篇关于Django缓存错误..即使禁用了缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆