Sha256: 6bb0012fc50e4c6c655122ff6856493d10b5d9446901ef5ceac33418d458fb72
Contents?: true
Size: 1.87 KB
Versions: 1
Compression:
Stored size: 1.87 KB
Contents
require 'active_support/cache' require 'action_dispatch/middleware/session/abstract_store' require 'dalli' # Dalli-based session store for Rails 3.0. module ActionDispatch module Session class DalliStore < AbstractStore def initialize(app, options = {}) # Support old :expires option options[:expire_after] ||= options[:expires] super @default_options = { :namespace => 'rack:session' }.merge(@default_options) @pool = options[:cache] || begin Dalli::Client.new( @default_options[:memcache_server], @default_options) end @namespace = @default_options[:namespace] super end def reset @pool.reset end private def get_session(env, sid) sid ||= generate_sid begin session = @pool.get(sid) || {} rescue Dalli::DalliError Rails.logger.warn("Session::DalliStore#get: #{$!.message}") session = {} end [sid, session] end def set_session(env, sid, session_data, options = nil) options ||= env[ENV_SESSION_OPTIONS_KEY] expiry = options[:expire_after] @pool.set(sid, session_data, expiry) sid rescue Dalli::DalliError Rails.logger.warn("Session::DalliStore#set: #{$!.message}") false end def destroy_session(env, session_id, options) @pool.delete(session_id) rescue Dalli::DalliError Rails.logger.warn("Session::DalliStore#destroy_session: #{$!.message}") false end def destroy(env) if sid = current_session_id(env) @pool.delete(sid) end rescue Dalli::DalliError Rails.logger.warn("Session::DalliStore#destroy: #{$!.message}") false end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dalli-1.1.1 | lib/action_dispatch/middleware/session/dalli_store.rb |