session store to memcache configure

今天遇到个问题,项目配置为,ruby1.8.7,rails 3.1.3 用到了session,要吧user的信息村到session去,为了偷懒,索性将user的所有信息都扔到了session里面,之后在运行的时候报错了:ActionDispatch::Cookies::CookieOverflow,这是因为rails默认的是将session的存储到cookie里面,又因为cookie对字串的大小限制为4k,当session内存储的信息大于4k的时候就会报这个错误,关于session信息的存储,网上有很多解决方案:

Cookie (default)
PStore
ActiveRecordStore
DRbStore
FileStore
MemoryStore


在这里说下将session存储到memcached,在rails3中,将下面的配置信息添加到config/application.rb文件中

require 'memcache'
memcache_options = {
:compression => true,
:debug => false,
:namespace => "cha_mem",
:readonly => false,
:urlencode => true
}

memcache_servers = ['localhost:11211']
cache_params = *([memcache_servers, memcache_options].flatten)
#
SESSION_CACHE = MemCache.new *cache_params

之后再在该文件的底部加上:

config.session_store = {
:key => '_ImNet',
:secret =>'81b83630687cb1049549ee12b8579c063985d6089702ef46c',
:cache => SESSION_CACHE,
:expires => 3600*24*7
}

注意:in rails2 The session_store was configured in ActionController::Base.session, and that is now(in rails 3) moved to Rails.application.config.session_store
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值