简体   繁体   English

Django数据库缓存

[英]Django Database Caching

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. 我认为使用Django交换memcached进行数据库或基于文件的缓存非常简单。 My memcached implementation works like a champ without any issues. 我的memcached实现就像一个没有任何问题的冠军。 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. 在运行所需的manage.py(createcachetable)行之后,该表存在,我可以很好地查看它。 I'm currently in testing, so I am using sqlite3, but that shouldn't matter as far as I can tell. 我目前正在测试,所以我使用sqlite3,但就我所知,这应该不重要。 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. 我正在使用sqlite3,Django 1.0.2,python 2.6,目前在Ubuntu Jaunty机器上通过Apache提供服务。 I'm sure I'm just glossing over something simple. 我敢肯定我只是简单地谈论一些事情。 Thanks for any help provided. 感谢您提供的任何帮助。

According to the documentation you're supposed to create the table not by using syncdb but with the following: 根据文档,您应该创建表而不是使用syncdb,但具有以下内容:

python manage.py createcachetable cache_table

If you haven't done that, try and see if it doesn't work. 如果您还没有这样做,请尝试查看它是否不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM