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. 6
      config/environments/production.rb
  5. 9
      config/initializers/session_store.rb

1
Gemfile

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

2
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)

12
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

6
config/environments/production.rb

@ -38,6 +38,12 @@ 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"

9
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

Loading…
Cancel
Save