Set up memcached¶
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
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.
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 (nginx, passenger, mongrel, thin..)
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