From b715da8e6f97629bb85b5dcc2b93b279bd172444 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Thu, 3 Nov 2011 04:41:52 -0700 Subject: [PATCH] memcache - sessions & cache --- Gemfile | 1 + Gemfile.lock | 2 ++ config/environment.rb | 12 ++++++++++++ config/environments/production.rb | 8 +++++++- config/initializers/session_store.rb | 9 ++++++++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index a31670e..00b67f2 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ group :assets do end gem 'jquery-rails' +gem 'dalli', '~> 1.1.3' # gem 'foreigner' ? group :test, :development do diff --git a/Gemfile.lock b/Gemfile.lock index d3ffc97..1a4c945 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,7 @@ GEM chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) + dalli (1.1.3) database_cleaner (0.6.7) devise (1.4.8) bcrypt-ruby (~> 3.0) @@ -222,6 +223,7 @@ DEPENDENCIES capybara (~> 1.1.1) coffee-rails (~> 3.1.0) compass (~> 0.12.alpha.0) + dalli (~> 1.1.3) database_cleaner (~> 0.6.7) devise (~> 1.4.5) factory_girl_rails (~> 1.2) diff --git a/config/environment.rb b/config/environment.rb index d4e6183..faccf54 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -3,3 +3,15 @@ require File.expand_path('../application', __FILE__) # Initialize the rails application Entrydns::Application.initialize! + +if defined?(PhusionPassenger) + PhusionPassenger.on_event(:starting_worker_process) do |forked| + # Reset Rails's object cache + # Only works with DalliStore + Rails.cache.reset if forked + + # Reset Rails's session store + # If you know a cleaner way to find the session store instance, please let me know + ObjectSpace.each_object(ActionDispatch::Session::DalliStore) { |obj| obj.reset } + end +end diff --git a/config/environments/production.rb b/config/environments/production.rb index 9866e8a..8677aa2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -38,7 +38,13 @@ Entrydns::Application.configure do # Use a different cache store in production # config.cache_store = :mem_cache_store - + config.cache_store = :dalli_store, 'localhost', { + :memcache_server => ['127.0.0.1'], + :namespace => 'entrydns', + :expires_in => 1.day, + :compress => true + } + # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 802254b..52c5bf0 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,6 +1,13 @@ # Be sure to restart your server when you modify this file. -Entrydns::Application.config.session_store :cookie_store, key: '_entrydns_session' +require 'action_dispatch/middleware/session/dalli_store' +Rails.application.config.session_store :dalli_store, + :memcache_server => ['127.0.0.1'], + :namespace => 'entrydns', + :key => '_entrydns_session', + :expire_after => 2.hours + +# Entrydns::Application.config.session_store :cookie_store, key: '_entrydns_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information