Browse Source

memcache - sessions & cache

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
b715da8e6f
  1. 1
      Gemfile
  2. 2
      Gemfile.lock
  3. 12
      config/environment.rb
  4. 8
      config/environments/production.rb
  5. 9
      config/initializers/session_store.rb

1
Gemfile

@ -32,6 +32,7 @@ group :assets do
end end
gem 'jquery-rails' gem 'jquery-rails'
gem 'dalli', '~> 1.1.3'
# gem 'foreigner' ? # gem 'foreigner' ?
group :test, :development do group :test, :development do

2
Gemfile.lock

@ -76,6 +76,7 @@ GEM
chunky_png (~> 1.2) chunky_png (~> 1.2)
fssm (>= 0.2.7) fssm (>= 0.2.7)
sass (~> 3.1) sass (~> 3.1)
dalli (1.1.3)
database_cleaner (0.6.7) database_cleaner (0.6.7)
devise (1.4.8) devise (1.4.8)
bcrypt-ruby (~> 3.0) bcrypt-ruby (~> 3.0)
@ -222,6 +223,7 @@ DEPENDENCIES
capybara (~> 1.1.1) capybara (~> 1.1.1)
coffee-rails (~> 3.1.0) coffee-rails (~> 3.1.0)
compass (~> 0.12.alpha.0) compass (~> 0.12.alpha.0)
dalli (~> 1.1.3)
database_cleaner (~> 0.6.7) database_cleaner (~> 0.6.7)
devise (~> 1.4.5) devise (~> 1.4.5)
factory_girl_rails (~> 1.2) factory_girl_rails (~> 1.2)

12
config/environment.rb

@ -3,3 +3,15 @@ require File.expand_path('../application', __FILE__)
# Initialize the rails application # Initialize the rails application
Entrydns::Application.initialize! 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

8
config/environments/production.rb

@ -38,7 +38,13 @@ Entrydns::Application.configure do
# Use a different cache store in production # Use a different cache store in production
# config.cache_store = :mem_cache_store # 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 # Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com" # config.action_controller.asset_host = "http://assets.example.com"

9
config/initializers/session_store.rb

@ -1,6 +1,13 @@
# Be sure to restart your server when you modify this file. # 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, # Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information # which shouldn't be used to store highly confidential information

Loading…
Cancel
Save