Parent

Class Index [+]

Quicksearch

Merb::MemorySessionStore

Used for handling multiple sessions stored in memory.

Public Class Methods

new(ttl=nil) click to toggle source

Parameters

ttl

Session validity time in seconds. Defaults to 1 hour.

:api: private

    # File 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

Public Instance Methods

delete_session(session_id) click to toggle source

Parameters

session_id

ID of the session to delete.

:api: private

    # File lib/merb-core/dispatch/session/memory.rb, line 82
82:     def delete_session(session_id)
83:       @mutex.synchronize {
84:         @timestamps.delete(session_id)
85:         @sessions.delete(session_id)
86:       }
87:     end
reap_expired_sessions() click to toggle source

Deletes any sessions that have reached their maximum validity.

:api: private

    # File 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
retrieve_session(session_id) click to toggle source

Parameters

session_id

ID of the session to retrieve.

Returns

ContainerSession

The session corresponding to the ID.

:api: private

    # File 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
start_timer() click to toggle source

Starts the timer that will eventually reap outdated sessions.

:api: private

     # File 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
store_session(session_id, data) click to toggle source

Parameters

session_id

ID of the session to set.

data

The session to set.

:api: private

    # File 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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.