Class: Jimmu::SessionStore
- Inherits:
-
Object
- Object
- Jimmu::SessionStore
- Defined in:
- lib/jimmu.rb
Overview
Thread-safe, in-memory server-side session store shared by the whole Application. Session data does not survive a server restart -- this is a development-focused framework, and adding a persistent backend is left as an extension point.
Constant Summary collapse
- COOKIE_NAME =
'_jimmu_session'- DEFAULT_MAX_AGE =
24 hours, refreshed on every response
60 * 60 * 24
Instance Method Summary collapse
- #destroy(session_id) ⇒ Object
-
#fetch_or_create(session_id) ⇒ Object
Returns [session_id, session_hash, newly_created].
-
#initialize ⇒ SessionStore
constructor
A new instance of SessionStore.
Constructor Details
#initialize ⇒ SessionStore
Returns a new instance of SessionStore.
640 641 642 643 |
# File 'lib/jimmu.rb', line 640 def initialize @sessions = {} @lock = Mutex.new end |
Instance Method Details
#destroy(session_id) ⇒ Object
658 659 660 |
# File 'lib/jimmu.rb', line 658 def destroy(session_id) @lock.synchronize { @sessions.delete(session_id) } end |
#fetch_or_create(session_id) ⇒ Object
Returns [session_id, session_hash, newly_created]
646 647 648 649 650 651 652 653 654 655 656 |
# File 'lib/jimmu.rb', line 646 def fetch_or_create(session_id) @lock.synchronize do if session_id && @sessions.key?(session_id) [session_id, @sessions[session_id], false] else id = SecureRandom.hex(16) @sessions[id] = {} [id, @sessions[id], true] end end end |