Project

General

Profile

Set up memcached » History » Revision 4

Revision 3 (Daniel Lobato Garcia, 11/21/2012 06:03 AM) → Revision 4/5 (Ohad Levy, 04/03/2013 04:20 AM)

h1. Set up memcached 

 h2. Using a Foreman Plugin (1.2 and newer) 

 as of Foreman 1.2, there is now a plugin with auto configures memcache usage, see [[List_of_Plugins]] 


 h2. Manual configuration (1.1 and below) 

 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, 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>