Rails 3 Memcached Session Store


Couldn’t be simpler in Rails 3.

Dalli is the new standard gem for dealing with memcached.

Gone are the days of “memcache, memcache-client, memcached” clusterfuck. Just use Dalli.

All theses steps are outlined in the Dalli README.

So if you don’t want to read the README here you go:
1. drop gem "dalli" in your Gemfile
2. In config/application.rb or config/environments/*.rb drop in config.cache_store = :dalli
3. In config/initializers/session_store.rb put the following:
require 'action_dispatch/middleware/session/dalli_store'
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 30.minutes

2 thoughts on “Rails 3 Memcached Session Store

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s