new Session()
Represents a browser session.
Sessions persist between HTTP requests for a single browser session. They are deleted when the browser is closed, or they time-out. Session cookies are used to maintain sessions using a secure UUID.
Sessions can be used to maintain data for a browser session, e.g. a shopping basket.
- Source:
Methods
-
destroy()
-
Destroy the session
- Source:
-
get(key) → {Object}
-
Get some data from the session
Parameters:
Name Type Description key
string the key of the data - Source:
Returns:
the data- Type
- Object
-
id() → {string}
-
- Source:
Returns:
-
The unique ID of the session. This is generated using a random secure UUID.
-
- Type
- string
-
isDestroyed() → {boolean}
-
- Source:
Returns:
-
has the session been destroyed?
-
- Type
- boolean
-
lastAccessed() → {number}
-
- Source:
Returns:
-
the time the session was last accessed
-
- Type
- number
-
put(key, obj) → {Session}
-
Put some data in a session
Parameters:
Name Type Description key
string the key for the data obj
Object the data - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- Session
-
remove(key) → {Object}
-
Remove some data from the session
Parameters:
Name Type Description key
string the key of the data - Source:
Returns:
the data that was there or null if none there- Type
- Object
-
setAccessed()
-
Mark the session as being accessed.
- Source:
-
timeout() → {number}
-
- Source:
Returns:
-
the amount of time in ms, after which the session will expire, if not accessed.
-
- Type
- number