diff options
author | José Valim <jose.valim@gmail.com> | 2010-09-20 10:18:44 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-10-03 21:24:22 +0200 |
commit | 50215f9525b6b5e3bfe703724b9f68177ed8565d (patch) | |
tree | 1574d048d9da01a941313592bf433431572497b9 /actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb | |
parent | 5836af8f8b0eb3c569c66792abf50a0485bb6f22 (diff) | |
download | rails-50215f9525b6b5e3bfe703724b9f68177ed8565d.tar.gz rails-50215f9525b6b5e3bfe703724b9f68177ed8565d.tar.bz2 rails-50215f9525b6b5e3bfe703724b9f68177ed8565d.zip |
Rely on Rack::Session stores API for more compatibility across the Ruby world.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb | 53 |
1 files changed, 7 insertions, 46 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb index 28e3dbd732..4dd9a946c2 100644 --- a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb @@ -1,56 +1,17 @@ +require 'action_dispatch/middleware/session/abstract_store' +require 'rack/session/memcache' + module ActionDispatch module Session - class MemCacheStore < AbstractStore + class MemCacheStore < Rack::Session::Memcache + include Compatibility + include StaleSessionCheck + def initialize(app, options = {}) require 'memcache' - - # Support old :expires option options[:expire_after] ||= options[:expires] - - super - - @default_options = { - :namespace => 'rack:session', - :memcache_server => 'localhost:11211' - }.merge(@default_options) - - @pool = options[:cache] || MemCache.new(@default_options[:memcache_server], @default_options) - unless @pool.servers.any? { |s| s.alive? } - raise "#{self} unable to find server during initialization." - end - @mutex = Mutex.new - super end - - private - def get_session(env, sid) - sid ||= generate_sid - begin - session = @pool.get(sid) || {} - rescue MemCache::MemCacheError, Errno::ECONNREFUSED - session = {} - end - [sid, session] - end - - def set_session(env, sid, session_data) - options = env['rack.session.options'] - expiry = options[:expire_after] || 0 - @pool.set(sid, session_data, expiry) - sid - rescue MemCache::MemCacheError, Errno::ECONNREFUSED - false - end - - def destroy(env) - if sid = current_session_id(env) - @pool.delete(sid) - end - rescue MemCache::MemCacheError, Errno::ECONNREFUSED - false - end - end end end |