Project

General

Profile

Actions

Set up memcached » History » Revision 2

« Previous | Revision 2/5 (diff) | Next »
Daniel Lobato Garcia, 11/21/2012 06:02 AM


Set up memcached

As a Rails 3 application, foreman is fairly easy to connect to memcached.
Instead of using memcache-client, we are going to use Dalli, a ruby gem that allows Rails to use your memcached store.

  • Include
    gem 'dalli'
    on your Gemfile and run bundle install.
  • Open your environment config file, it is in config/environments/*.rb. Let's assume you will want to set memcached as your production cache store. (config/environments/production.rb)
  • Add the following line in the Foreman::Aplication.configure block.
    config.cache_store = :dalli_store
  • Reboot your server (Webrick, passenger, mongrel, thin..)

Additional options

If you have your own separate cache servers, just add it after the command like this:

config.cache_store = :dalli_store, 'cache1.myserver.com', 'cache2.myserver.com'

Memcached can be used to manage sessions, just add something like this to your config/initializers/session_store.rb:
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 => 20.minutes

Updated by Daniel Lobato Garcia about 12 years ago · 5 revisions