Rack::Session::Pool provides simple cookie based session management. Session data is stored in a hash held by @pool. In the context of a multithreaded environment, sessions being committed to the pool is done in a merging manner.

The :drop option is available in rack.session.options if you wish to explicitly remove the session from the session cache.

Example:

myapp = MyRackApp.new
sessioned = Rack::Session::Pool.new(myapp,
  :domain => 'foo.com',
  :expire_after => 2592000
)
Rack::Handler::WEBrick.run sessioned
Methods
D
F
G
N
W
Constants
DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :drop => false
 
Attributes
[R] mutex
[R] pool
Class Public methods
new(app, options={})
# File lib/rack/session/pool.rb, line 31
def initialize(app, options={})
  super
  @pool = Hash.new
  @mutex = Mutex.new
end
Instance Public methods
delete_session(req, session_id, options)
# File lib/rack/session/pool.rb, line 61
def delete_session(req, session_id, options)
  with_lock(req) do
    @pool.delete(session_id)
    generate_sid unless options[:drop]
  end
end
find_session(req, sid)
# File lib/rack/session/pool.rb, line 44
def find_session(req, sid)
  with_lock(req) do
    unless sid and session = @pool[sid]
      sid, session = generate_sid, {}
      @pool.store sid, session
    end
    [sid, session]
  end
end
generate_sid()
# File lib/rack/session/pool.rb, line 37
def generate_sid
  loop do
    sid = super
    break sid unless @pool.key? sid
  end
end
with_lock(req)
# File lib/rack/session/pool.rb, line 68
def with_lock(req)
  @mutex.lock if req.multithread?
  yield
ensure
  @mutex.unlock if @mutex.locked?
end
write_session(req, session_id, new_session, options)
# File lib/rack/session/pool.rb, line 54
def write_session(req, session_id, new_session, options)
  with_lock(req) do
    @pool.store session_id, new_session
    session_id
  end
end