Class: Rack::Session::Pool
- Inherits:
-
Abstract::PersistedSecure
- Object
- Abstract::Persisted
- Abstract::PersistedSecure
- Rack::Session::Pool
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/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 collapse
- DEFAULT_OPTIONS =
Abstract::ID::DEFAULT_OPTIONS.merge drop: false
Instance Attribute Summary collapse
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
Attributes inherited from Abstract::Persisted
#default_options, #key, #sid_secure
Instance Method Summary collapse
- #delete_session(req, session_id, options) ⇒ Object
- #find_session(req, sid) ⇒ Object
- #generate_sid ⇒ Object
-
#initialize(app, options = {}) ⇒ Pool
constructor
A new instance of Pool.
- #with_lock(req) ⇒ Object
- #write_session(req, session_id, new_session, options) ⇒ Object
Methods inherited from Abstract::PersistedSecure
Methods inherited from Abstract::Persisted
#call, #commit_session, #context
Constructor Details
Instance Attribute Details
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
30 31 32 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/pool.rb', line 30 def mutex @mutex end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
30 31 32 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/pool.rb', line 30 def pool @pool end |
Instance Method Details
#delete_session(req, session_id, options) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/pool.rb', line 63 def delete_session(req, session_id, ) with_lock(req) do @pool.delete(session_id.public_id) @pool.delete(session_id.private_id) generate_sid unless [:drop] end end |
#find_session(req, sid) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/pool.rb', line 46 def find_session(req, sid) with_lock(req) do unless sid and session = get_session_with_fallback(sid) sid, session = generate_sid, {} @pool.store sid.private_id, session end [sid, session] end end |
#generate_sid ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/pool.rb', line 39 def generate_sid loop do sid = super break sid unless @pool.key? sid.private_id end end |
#with_lock(req) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/pool.rb', line 71 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) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/session/pool.rb', line 56 def write_session(req, session_id, new_session, ) with_lock(req) do @pool.store session_id.private_id, new_session session_id end end |