session_store=(store) public

Set the session store to be used for keeping the session data between requests. The default is using the file system, but you can also specify one of the other included stores (:active_record_store, :drb_store, :mem_cache_store, or :memory_store) or use your own class.

Show source
Register or log in to add new notes.
June 18, 2008
8 thanks

Using memcached as a session store

Because of Ruby’s CGI library limitations, store cannot have any configuration options. Basically this means that you cannot easily run memcached on a different port (or with any non-default settings for that matter).

You can bypass this limitation with this ugly hack (environment.rb):

cache_params = *([memcache_servers, memcache_options].flatten)
CACHE = MemCache.new(*cache_params)
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.merge!({ 'cache' => CACHE })

In your initializer block, just configure session_store normally:

config.session_store = :mem_cache_store

I think this should be fixed to work like cache_store= does.