Determines how many times to try generating a unique session key before we give up
Generates a new session ID and creates a new session.
SessionStoreContainer | The new session. |
:api: private
# File lib/merb-core/dispatch/session/store_container.rb, line 59 59: def generate 60: 61: # make sure we generate a unique session uuid 62: sid = nil 63: GENERATE_MAX_TRIES.times do |i| 64: sid = Merb::SessionMixin.rand_uuid 65: data = store.retrieve_session(sid) rescue nil 66: break if data.nil? 67: raise "Unable to Generate Unique Session key" if i == (GENERATE_MAX_TRIES-1) 68: end 69: 70: session = new(sid) 71: session.needs_new_cookie = true 72: session 73: end
Setup a new session or retreive an existing session.
request | The Merb::Request that came in from Rack. |
If no sessions were found, a new SessionContainer will be generated.
SessionContainer |
:api: private
# File lib/merb-core/dispatch/session/store_container.rb, line 87 87: def setup(request) 88: session = retrieve(request.session_id) 89: request.session = session 90: # TODO Marshal.dump is slow - needs optimization 91: session._fingerprint = Marshal.dump(request.session.to_hash).hash 92: session 93: end
session_id<String | The ID of the session to retrieve. |
SessionStoreContainer | SessionStoreContainer instance with the session data. If no |
sessions matched session_id, a new SessionStoreContainer will be generated.
If there are persisted exceptions callbacks to execute, they all get executed when Memcache library raises an exception.
:api: private
# File lib/merb-core/dispatch/session/store_container.rb, line 109 109: def retrieve(session_id) 110: unless session_id.blank? 111: begin 112: session_data = store.retrieve_session(session_id) 113: rescue => err 114: Merb.logger.warn!("Could not retrieve session from #{self.name}: #{err.message}") 115: end 116: # Not in container, but assume that cookie exists 117: session_data = new(session_id) if session_data.nil? 118: else 119: # No cookie...make a new session_id 120: session_data = generate 121: end 122: if session_data.is_a?(self) 123: session_data 124: else 125: # Recreate using the existing session as the data, when switching 126: # from another session type for example, eg. cookie to memcached 127: # or when the data is just a hash 128: new(session_id).update(session_data) 129: end 130: end
Teardown and/or persist the current session.
If @_destroy is true, clear out the session completely, including removal of the session cookie itself.
request | The Merb::Request that came in from Rack. |
The data (self) is converted to a Hash first, since a container might choose to do a full Marshal on the data, which would make it persist attributes like ‘needs_new_cookie’, which it shouldn’t.
:api: private
# File lib/merb-core/dispatch/session/store_container.rb, line 148 148: def finalize(request) 149: if @_destroy 150: store.delete_session(self.session_id) 151: request.destroy_session_cookie 152: else 153: if _fingerprint != Marshal.dump(data = self.to_hash).hash 154: begin 155: store.store_session(request.session(self.class.session_store_type).session_id, data) 156: rescue => err 157: Merb.logger.warn!("Could not persist session to #{self.class.name}: #{err.message}") 158: end 159: end 160: if needs_new_cookie || Merb::SessionMixin.needs_new_cookie? 161: request.set_session_id_cookie(self.session_id) 162: end 163: end 164: end
Regenerate the session ID.
:api: private
# File lib/merb-core/dispatch/session/store_container.rb, line 169 169: def regenerate 170: store.delete_session(self.session_id) 171: self.session_id = Merb::SessionMixin.rand_uuid 172: store.store_session(self.session_id, self) 173: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.