Feature #196

Adding Redmine to a Centralized Memcache Server

Added by Daniel Curtis about 8 years ago. Updated over 6 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:
1.00 h
Spent time:


I encountered the need to have centralized session management for the multiple instances of the same content. This is where memcache comes in. First the gem for memcache needs to be installed:

sudo gem install memcache-client

Next, add the environment code to the end of config/environment.rb to utilize the memcache server:
# Load memcache
require 'memcache'

config.action_controller.session_store = :mem_cache_store

memcache_options = {
   :compression => true,
   :debug => false,
   :namespace => "mem-#{RAILS_ENV}",
   :readonly => false,
   :urlencode => false

memcache_servers = [ 'memcacheIP:11211' ]

CACHE.servers = memcache_servers
ActionController::Base.session_options[:cache] = CACHE


Updated by Daniel Curtis about 8 years ago

After deploying the above implementation, my instance of redmine broke. I could not find a proper guide to connecting redmine to a memcache server for session management. I did find an implementation for the foreman ruby application at
I have adapted the implementation to redmine, with a few minor adjustments.

Set up memcached

Instead of using memcache-client, we are going to use Dalli, a ruby gem that allows Rails to use your memcached store.

Include this in your Gemfile

gem 'dalli'

Then 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, such as config/environments/production.rb

Add the following line in the RedmineApp::Application.configure block

config.cache_store = :dalli_store

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:

config.cache_store = :dalli_store, '', ''

Use memcached to manage sessions

Just add something like this to your config/environment.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


Updated by Daniel Curtis over 7 years ago

I found a better way to cache sessions, still using the dalli gem however:

vi /path/to/redmine/config/environments/production.rb

Then add the following right after RedmineApp::Application.configure do:

# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.perform_caching = true
# config.cache_store = :dalli_store
require 'action_dispatch/middleware/session/dalli_store'
Rails.application.config.session_store :dalli_store \
, :memcache_server => ['localhost', ''] \
, :namespace => 'sessions'    \
, :key => '_foundation_session'    \
, :expire_after => 20.minutes    \
, :compress => true    \
, :compressor => Dalli::GzipCompressor    \
, :keepalive => true    \
, :expires_in => 5.minutes    
  #config.cache_store = :dalli_store, 'localhost',
  #{ :namespace => "redmine_pro", :expires_in => 3600, :compress => true }

# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "" 


Updated by Daniel Curtis over 6 years ago

  • Project changed from 24 to Website Hosting

Also available in: Atom PDF