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