Class | Merb::MemorySessionStore |
In: |
merb-core/lib/merb-core/dispatch/session/memory.rb
|
Parent: | Object |
Used for handling multiple sessions stored in memory.
ttl<Fixnum>: | Session validity time in seconds. Defaults to 1 hour. |
:api: private
# File merb-core/lib/merb-core/dispatch/session/memory.rb, line 44 44: def initialize(ttl=nil) 45: @sessions = Hash.new 46: @timestamps = Hash.new 47: @mutex = Mutex.new 48: @session_ttl = ttl || Merb::Const::HOUR # defaults 1 hour 49: start_timer 50: end
Deletes any sessions that have reached their maximum validity.
:api: private
# File merb-core/lib/merb-core/dispatch/session/memory.rb, line 92 92: def reap_expired_sessions 93: @timestamps.each do |session_id,stamp| 94: delete_session(session_id) if (stamp + @session_ttl) < Time.now 95: end 96: GC.start 97: end
session_id<String>: | ID of the session to retrieve. |
ContainerSession: | The session corresponding to the ID. |
:api: private
# File merb-core/lib/merb-core/dispatch/session/memory.rb, line 59 59: def retrieve_session(session_id) 60: @mutex.synchronize { 61: @timestamps[session_id] = Time.now 62: @sessions[session_id] 63: } 64: end
Starts the timer that will eventually reap outdated sessions.
:api: private
# File merb-core/lib/merb-core/dispatch/session/memory.rb, line 102 102: def start_timer 103: Thread.new do 104: loop { 105: sleep @session_ttl 106: reap_expired_sessions 107: } 108: end 109: end
session_id<String>: | ID of the session to set. |
data<ContainerSession>: | The session to set. |
:api: private
# File merb-core/lib/merb-core/dispatch/session/memory.rb, line 71 71: def store_session(session_id, data) 72: @mutex.synchronize { 73: @timestamps[session_id] = Time.now 74: @sessions[session_id] = data 75: } 76: end