Class: Rack::Session::Pool
- Inherits:
-
Abstract::ID
- Object
- Abstract::ID
- Rack::Session::Pool
- Defined in:
- rack/rack/session/pool.rb
Overview
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
Constant Summary
- DEFAULT_OPTIONS =
Abstract::ID::DEFAULT_OPTIONS.merge :drop => false
Instance Attribute Summary (collapse)
-
- (void) default_options
inherited
from Abstract::ID
readonly
Returns the value of attribute default_options.
-
- (void) key
inherited
from Abstract::ID
readonly
Returns the value of attribute key.
-
- (void) mutex
readonly
Returns the value of attribute mutex.
-
- (void) pool
readonly
Returns the value of attribute pool.
Instance Method Summary (collapse)
- - (void) destroy_session(env, session_id, options)
- - (void) generate_sid
- - (void) get_session(env, sid)
-
- (Pool) initialize(app, options = {})
constructor
A new instance of Pool.
- - (void) set_session(env, session_id, new_session, options)
- - (void) with_lock(env, default = nil)
Constructor Details
- (Pool) initialize(app, options = {})
Returns a new instance of Pool
31 32 33 34 35 |
# File 'rack/rack/session/pool.rb', line 31 def initialize(app, ={}) super @pool = Hash.new @mutex = Mutex.new end |
Instance Attribute Details
- (void) default_options (readonly) Originally defined in class Abstract::ID
Returns the value of attribute default_options
- (void) key (readonly) Originally defined in class Abstract::ID
Returns the value of attribute key
- (void) mutex (readonly)
Returns the value of attribute mutex
28 29 30 |
# File 'rack/rack/session/pool.rb', line 28 def mutex @mutex end |
- (void) pool (readonly)
Returns the value of attribute pool
28 29 30 |
# File 'rack/rack/session/pool.rb', line 28 def pool @pool end |
Instance Method Details
- (void) destroy_session(env, session_id, options)
61 62 63 64 65 66 |
# File 'rack/rack/session/pool.rb', line 61 def destroy_session(env, session_id, ) with_lock(env) do @pool.delete(session_id) generate_sid unless [:drop] end end |
- (void) generate_sid
37 38 39 40 41 42 |
# File 'rack/rack/session/pool.rb', line 37 def generate_sid loop do sid = super break sid unless @pool.key? sid end end |
- (void) get_session(env, sid)
44 45 46 47 48 49 50 51 52 |
# File 'rack/rack/session/pool.rb', line 44 def get_session(env, sid) with_lock(env, [nil, {}]) do unless sid and session = @pool[sid] sid, session = generate_sid, {} @pool.store sid, session end [sid, session] end end |
- (void) set_session(env, session_id, new_session, options)
54 55 56 57 58 59 |
# File 'rack/rack/session/pool.rb', line 54 def set_session(env, session_id, new_session, ) with_lock(env, false) do @pool.store session_id, new_session session_id end end |
- (void) with_lock(env, default = nil)
68 69 70 71 72 73 74 75 |
# File 'rack/rack/session/pool.rb', line 68 def with_lock(env, default=nil) @mutex.lock if env['rack.multithread'] yield rescue default ensure @mutex.unlock if @mutex.locked? end |