Project

General

Profile

Set up memcached » History » Revision 3

Revision 2 (Daniel Lobato Garcia, 11/21/2012 06:02 AM) → Revision 3/5 (Daniel Lobato Garcia, 11/21/2012 06:03 AM)

h1. 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 <pre>gem 'dalli'</pre> 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. <pre>config.cache_store = :dalli_store</pre>  
 * Reboot your server (nginx, (Webrick, passenger, mongrel, thin..) 

 +Additional options+ 

 If you have your own separate cache servers, just add it after the command like this:  
 <pre> 
 config.cache_store = :dalli_store, 'cache1.myserver.com', 'cache2.myserver.com' 
 </pre> 
  Memcached can be used to manage sessions, just add something like this to your config/initializers/session_store.rb: 
 <pre> 
 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 
 </pre>