Class: Merb::MemorySessionStore
- Inherits:
-
Object
- Object
- Merb::MemorySessionStore
- Defined in:
- merb-core/lib/merb-core/dispatch/session/memory.rb
Overview
Used for handling multiple sessions stored in memory.
Instance Method Summary (collapse)
- - (Object) delete_session(session_id) private
-
- (MemorySessionStore) initialize(ttl = nil)
constructor
private
A new instance of MemorySessionStore.
-
- (Object) reap_expired_sessions
private
Deletes any sessions that have reached their maximum validity.
- - (Object) retrieve_session(session_id) private
-
- (Object) start_timer
private
Starts the timer that will eventually reap outdated sessions.
- - (Object) store_session(session_id, data) private
Constructor Details
- (MemorySessionStore) initialize(ttl = nil)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A new instance of MemorySessionStore
45 46 47 48 49 50 51 |
# File 'merb-core/lib/merb-core/dispatch/session/memory.rb', line 45 def initialize(ttl=nil) @sessions = Hash.new @timestamps = Hash.new @mutex = Mutex.new @session_ttl = ttl || Merb::Const::HOUR # defaults 1 hour start_timer end |
Instance Method Details
- (Object) delete_session(session_id)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 |
# File 'merb-core/lib/merb-core/dispatch/session/memory.rb', line 70 def delete_session(session_id) @mutex.synchronize { @timestamps.delete(session_id) @sessions.delete(session_id) } end |
- (Object) reap_expired_sessions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes any sessions that have reached their maximum validity.
80 81 82 83 84 85 |
# File 'merb-core/lib/merb-core/dispatch/session/memory.rb', line 80 def reap_expired_sessions @timestamps.each do |session_id,stamp| delete_session(session_id) if (stamp + @session_ttl) < Time.now end GC.start end |
- (Object) retrieve_session(session_id)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 57 58 59 |
# File 'merb-core/lib/merb-core/dispatch/session/memory.rb', line 54 def retrieve_session(session_id) @mutex.synchronize { @timestamps[session_id] = Time.now @sessions[session_id] } end |
- (Object) start_timer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Starts the timer that will eventually reap outdated sessions.
90 91 92 93 94 95 96 97 |
# File 'merb-core/lib/merb-core/dispatch/session/memory.rb', line 90 def start_timer Thread.new do loop { sleep @session_ttl reap_expired_sessions } end end |
- (Object) store_session(session_id, data)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 |
# File 'merb-core/lib/merb-core/dispatch/session/memory.rb', line 62 def store_session(session_id, data) @mutex.synchronize { @timestamps[session_id] = Time.now @sessions[session_id] = data } end |