Sha256: 63ba4bfa1cb5570c8bf132955e002586cae6c685dea844fc002448b495d424a4

Contents?: true

Size: 1.44 KB

Versions: 48

Compression:

Stored size: 1.44 KB

Contents

begin
  require_library_or_gem 'memcache'

  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
      end
    end
  end
rescue LoadError
  # MemCache wasn't available so neither can the store be
end

Version data entries

48 entries across 47 versions & 9 rubygems

Version Path
actionpack_csi-2.3.5.p8 lib/action_controller/session/mem_cache_store.rb
actionpack_csi-2.3.5.p7 lib/action_controller/session/mem_cache_store.rb
actionpack_csi-2.3.5.p6 lib/action_controller/session/mem_cache_store.rb
webroar-0.5.0 src/admin_panel/vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.2.4 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.2.2 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.2.1 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.2 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.9 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.8 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.7 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.6 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.5 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.4 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.3 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.2 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1.1 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiantcms-couchrest_model-0.1 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
webroar-0.4.0 src/admin_panel/vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb
radiant-0.9.1 vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb