我在使用 Memcached 存储 session 的时候,遇到了一个非常奇怪的问题。偶尔会出现某些用户获取到了其他用户的 session,比如 John 登录后变成了 Maria,Maria 变成了 Chris 等等。
我使用的是 Rails 2.3.4,但之前的版本也存在这个问题。我只使用了一台 Memcache 服务器,而且它和我的应用运行在同一台机器上。调试这个问题的困难在于我无法复现它。
如果有人能指导我如何解决或调试这个问题,我将不胜感激。如果你正在使用 Memcached 来存储 session,并可以分享你的示例配置,我也会很高兴的。
以下是我的配置:
# memcache options
memcache_options = {
:c_threshold => 10_000,
:compression => false,
:debug => false,
:namespace => 'app_prod',
:readonly => false,
:urlencode => false,
}
memcache_servers = ['localhost:11211']
CACHE = MemCache.new(memcache_options)
CACHE.servers = memcache_servers
config.cache_store = :mem_cache_store, memcache_servers, memcache_options
config.action_controller.session_store = :mem_cache_store
config.action_controller.session = {
:session_key => '_appname',
:cache => CACHE,
# :expires => 10,
# :session_expires => 10,
:secret => '5391aaaaaaaaaa56f8e8234beb638b97b32bbbbbbbbbbcc9dcae2beccccccccc89e8b508328def001a368da0678b061eb0e9d5a82a5ac94c8d35bd31a9a49e1'
}
事先感谢您,
Stan