Class: KStor::SessionStore
- Inherits:
-
Object
- Object
- KStor::SessionStore
- Defined in:
- lib/kstor/session.rb
Overview
Collection of user sessions (in memory)
FIXME make it thread safe!
Instance Method Summary collapse
- #<<(session) ⇒ Object
- #[](sid) ⇒ Object
-
#initialize(idle_timeout, life_timeout) ⇒ SessionStore
constructor
A new instance of SessionStore.
- #purge ⇒ Object
Constructor Details
#initialize(idle_timeout, life_timeout) ⇒ SessionStore
Returns a new instance of SessionStore.
37 38 39 40 41 42 |
# File 'lib/kstor/session.rb', line 37 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
44 45 46 47 48 |
# File 'lib/kstor/session.rb', line 44 def <<(session) @sessions.synchronize do @sessions[session.id] = session end end |
#[](sid) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kstor/session.rb', line 50 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
64 65 66 67 68 69 |
# File 'lib/kstor/session.rb', line 64 def purge now = Time.now @sessions.synchronize do @sessions.delete_if { |_, s| invalid?(s, now) } end end |