本站首页    管理页面    写新日志    退出


«November 2025»
1
2345678
9101112131415
16171819202122
23242526272829
30


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7652578
建立时间:2006年5月29日




[Ruby on Rails]一个非常不错的缓存方法,把缓存的结果放在数据库,节省内存!(转)
软件技术

lhwork 发表于 2007/1/19 15:55:27

http://www.bigbold.com/snippets/posts/show/3286Rails memcached is not very easy to introduce to a large rails installation. Memcached also chews up a lot of memory on the box and overall cached model does not work the way I needed it to. Basically, I have just a “few” queries that I needed to cache because pagination sucks just that bad in rails. So, I built my own cache, similar to how I build them in PHP except I am not using disk cache, I am using MySQL itself to cache it’s own results First, we need a table to hold all this info (note the ‘blob’ field) 代码 CREATE TABLE `cacheditems` (    `id` int(11) NOT NULL auto_increment,    `cachekey` varchar(255) default NULL,    `created` datetime default NULL,    `expires` datetime default NULL,    `content` longblob,    `cachehit` int(11) NOT NULL,    PRIMARY KEY  (`id`),    KEY `cacheditems_cachekey_index` (`cachekey`),    KEY `cacheditems_created_index` (`created`),    KEY `cacheditems_expires_index` (`expires`)    )   just throw “_cache” after any “find_by_sql” statement you have a need to cache and there you are. This works very fast, very well, and doesn’t hog your memory. It cleans up after itself in the database, and perhaps it does that too much.. It would be easy to add in a standard garbage collection function which runs on a random but I felt this gave me much better stats of the actual thirty-minute cache… If you use zabbix for monitoring your network, you can have fun graphs of cache statistics by adding the following to your zabbix_agentd.conf


阅读全文(3514) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144811879 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号