Django 数据库缓存
我正在开发一个小项目,我想为最终用户提供多个缓存选项。 我认为 Django 将 memcached 替换为基于数据库或文件的缓存非常简单。 我的 memcached 实现工作得很好,没有任何问题。 我在页面上放置了时间戳,curl 在我希望缓存正常工作的位置始终显示较旧的时间戳。 但是,当我切换到数据库缓存时,我在数据库中没有获得任何条目,并且缓存明显不起作用。
从我在文档中看到的所有必要的操作是将后端从: 更改
CACHE_BACKEND = 'memcached://localhost:11211'
为:
CACHE_BACKEND = 'db://cache_table'
运行所需的manage.py(createcachetable)行后该表存在,并且我可以很好地查看它。 我目前正在测试,所以我正在使用 sqlite3,但据我所知,这应该不重要。 我可以确认该表完全是空的,并且在任何时候都没有被写入。 另外,正如我之前所说,我的时间戳也是“错误的”,这给了我更多证据表明有些事情不太正确。
有什么想法吗? 我正在使用 sqlite3、Django 1.0.2、python 2.6,目前在 Ubuntu Jaunty 机器上通过 Apache 提供服务。 我确信我只是掩盖了一些简单的事情。 感谢您提供的任何帮助。
I'm working on a small project, and I wanted to provide multiple caching options to the end user. I figured with Django it's pretty simplistic to swap memcached for database or file based caching. My memcached implementation works like a champ without any issues. I placed time stamps on my pages, and curl consistently shows the older timestamps in locations where I want caching to work properly. However, when I switch over to the database caching, I don't get any entries in the database, and caching blatantly doesn't work.
From what I see in the documentation all that should be necessary is to change the backend from:
CACHE_BACKEND = 'memcached://localhost:11211'
To:
CACHE_BACKEND = 'db://cache_table'
The table exists after running the required manage.py (createcachetable) line, and I can view it just fine. I'm currently in testing, so I am using sqlite3, but that shouldn't matter as far as I can tell. I can confirm that the table is completely empty, and hasn't been written to at any point. Also, as I stated previously, my timestamps are 'wrong' as well, giving me more evidence that something isn't quite right.
Any thoughts? I'm using sqlite3, Django 1.0.2, python 2.6, serving via Apache currently on an Ubuntu Jaunty machine. I'm sure I'm just glossing over something simple. Thanks for any help provided.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据文档,您应该不使用syncdb而是使用以下内容创建表:
如果您还没有这样做,请尝试看看它是否不起作用。
According to the documentation you're supposed to create the table not by using syncdb but with the following:
If you haven't done that, try and see if it doesn't work.