class Rack::Session::Pool
def delete_session(req, session_id, options)
def delete_session(req, session_id, options) @mutex.synchronize do @pool.delete(session_id.public_id) @pool.delete(session_id.private_id) generate_sid(use_mutex: false) unless options[:drop] end end
def find_session(req, sid)
def find_session(req, sid) @mutex.synchronize do unless sid and session = get_session_with_fallback(sid) sid, session = generate_sid(use_mutex: false), {} @pool.store sid.private_id, session end [sid, session] end end
def generate_sid(*args, use_mutex: true)
def generate_sid(*args, use_mutex: true) loop do sid = super(*args) break sid unless use_mutex ? @mutex.synchronize { @pool.key? sid.private_id } : @pool.key?(sid.private_id) end end
def get_session_with_fallback(sid)
def get_session_with_fallback(sid) @pool[sid.private_id] || (@pool[sid.public_id] if @allow_fallback) end
def initialize(app, options = {})
def initialize(app, options = {}) super @pool = Hash.new @mutex = Mutex.new @allow_fallback = @default_options.delete(:allow_fallback) end
def write_session(req, session_id, new_session, options)
def write_session(req, session_id, new_session, options) @mutex.synchronize do @pool.store session_id.private_id, new_session session_id end end