diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-10-06 12:11:38 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2010-10-06 12:11:38 +0100 |
commit | c954d54e2f36bb53ced5e3655adc071dd233797e (patch) | |
tree | d84bf4bf51f65a1c817089c6fe37c3e9f20420d0 /actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb | |
parent | f2b41914d6be935182d37e0c0d491352ac3de043 (diff) | |
parent | d40ca9cce241a8083756c993d6c99a79e62e050e (diff) | |
download | rails-c954d54e2f36bb53ced5e3655adc071dd233797e.tar.gz rails-c954d54e2f36bb53ced5e3655adc071dd233797e.tar.bz2 rails-c954d54e2f36bb53ced5e3655adc071dd233797e.zip |
Merge branch 'master' into nested_has_many_through
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 |