Skip to content

Instantly share code, notes, and snippets.

@paulovittor23
Created October 29, 2012 16:53
Show Gist options
  • Save paulovittor23/3974852 to your computer and use it in GitHub Desktop.
Save paulovittor23/3974852 to your computer and use it in GitHub Desktop.
memcached session store
# Memcached config
memcache_config = YAML.load_file("#{RAILS_ROOT}/config/memcached.yml")[RAILS_ENV]
if memcache_config.nil?
raise ArgumentError.new("[ environment.rb ] Memcached configurations could not be found for RAILS_ENV => #{RAILS_ENV}")
end
require 'memcache'
CACHE = MemCache.new(:namespace => "abril-id-#{RAILS_ENV}")
CACHE.servers = memcache_config['servers']
config.action_controller.session_store = :mem_cache_store
config.action_controller.session = {
:session_key => '_abril_id_session',
:secret => '49d3fc7d49f23bc2a2fe7f755d3b466bbb4e02121d980acb0f6c7b6e32d9697a458b5cf583e26d27c3ad8e4743a48ec9d4d93bd2d7c2fad1e3e32b6f09f2e971',
:cache => CACHE,
:expires => memcache_config['expires']
}
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
CACHE.reset
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment