Class: KStor::SessionStore
- Inherits:
-
Object
- Object
- KStor::SessionStore
- Defined in:
- lib/kstor/session.rb
Overview
Collection of user sessions (in memory).
Concurrent accesses are synchronized on a mutex.
Instance Method Summary collapse
-
#<<(session) ⇒ Object
Add a session to the store.
-
#[](sid) ⇒ KStor::Session?
Fetch a session from it’s ID.
-
#initialize(idle_timeout, life_timeout) ⇒ KStor::SessionStore
constructor
Create new session store.
-
#purge ⇒ Object
Delete expired sessions.
Constructor Details
#initialize(idle_timeout, life_timeout) ⇒ KStor::SessionStore
Create new session store.
60 61 62 63 64 65 |
# File 'lib/kstor/session.rb', line 60 def initialize(idle_timeout, life_timeout) @idle_timeout = idle_timeout @life_timeout = life_timeout @sessions = {} @sessions.extend(Mutex_m) end |
Instance Method Details
#<<(session) ⇒ Object
Add a session to the store.
70 71 72 73 74 |
# File 'lib/kstor/session.rb', line 70 def <<(session) @sessions.synchronize do @sessions[session.id] = session end end |
#[](sid) ⇒ KStor::Session?
Fetch a session from it’s ID.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kstor/session.rb', line 81 def [](sid) @sessions.synchronize do s = @sessions[sid.to_s] return nil if s.nil? if invalid?(s) @sessions.delete(s.id) return nil end s.update end end |
#purge ⇒ Object
Delete expired sessions.
96 97 98 99 100 101 |
# File 'lib/kstor/session.rb', line 96 def purge now = Time.now @sessions.synchronize do @sessions.delete_if { |_, s| invalid?(s, now) } end end |