Set up memcached » History » Version 3
Daniel Lobato Garcia, 11/21/2012 06:03 AM
1 | 1 | Daniel Lobato Garcia | h1. Set up memcached |
---|---|---|---|
2 | |||
3 | As a Rails 3 application, foreman is fairly easy to connect to memcached. |
||
4 | Instead of using memcache-client, we are going to use Dalli, a ruby gem that allows Rails to use your memcached store. |
||
5 | |||
6 | * Include <pre>gem 'dalli'</pre> on your Gemfile and run *bundle install*. |
||
7 | * 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) |
||
8 | * Add the following line in the Foreman::Aplication.configure block. <pre>config.cache_store = :dalli_store</pre> |
||
9 | 3 | Daniel Lobato Garcia | * Reboot your server (nginx, passenger, mongrel, thin..) |
10 | 1 | Daniel Lobato Garcia | |
11 | +Additional options+ |
||
12 | |||
13 | If you have your own separate cache servers, just add it after the command like this: |
||
14 | <pre> |
||
15 | config.cache_store = :dalli_store, 'cache1.myserver.com', 'cache2.myserver.com' |
||
16 | </pre> |
||
17 | Memcached can be used to manage sessions, just add something like this to your config/initializers/session_store.rb: |
||
18 | <pre> |
||
19 | require 'action_dispatch/middleware/session/dalli_store' |
||
20 | Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes |
||
21 | </pre> |