Sha256: 3f3c5ddbfda4f279cde01c5e0f4878a5acce50913cb9af798b4cdffcb25478df

Contents?: true

Size: 1.69 KB

Versions: 15

Compression:

Stored size: 1.69 KB

Contents

begin
  require_library_or_gem 'memcache'
  require 'thread'
  module ActionController
    module Session
      class MemCacheStore < AbstractStore
        def initialize(app, options = {})
          # 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)
            return true
          rescue MemCache::MemCacheError, Errno::ECONNREFUSED
            return 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
rescue LoadError
  # MemCache wasn't available so neither can the store be
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
actionpack-2.3.18 lib/action_controller/session/mem_cache_store.rb
actionpack-2.3.17-rack-upgrade-2.3.17 lib/action_controller/session/mem_cache_store.rb
actionpack-2.3.17 lib/action_controller/session/mem_cache_store.rb
actionpack-2.3.16 lib/action_controller/session/mem_cache_store.rb
actionpack-rack-upgrade-2-2.3.16 lib/action_controller/session/mem_cache_store.rb
actionpack-rack-upgrade-2-2.3.15 lib/action_controller/session/mem_cache_store.rb
actionpack-2.3.15 lib/action_controller/session/mem_cache_store.rb
actionpack-rack-upgrade-2.3.16 lib/action_controller/session/mem_cache_store.rb
actionpack-rack-upgrade-2.3.15 lib/action_controller/session/mem_cache_store.rb
actionpack-rack-upgrade-2.3.14 lib/action_controller/session/mem_cache_store.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/actionpack-2.3.14/lib/action_controller/session/mem_cache_store.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/actionpack-2.3.12/lib/action_controller/session/mem_cache_store.rb
actionpack-2.3.14 lib/action_controller/session/mem_cache_store.rb
actionpack-2.3.12 lib/action_controller/session/mem_cache_store.rb
actionpack-2.3.11 lib/action_controller/session/mem_cache_store.rb