const mixinafBedSheet::HttpSession

afBedSheet::HttpSession

(Service) - An injectable const version of WebSession.

Provides a name/value map associated with a specific browser connection to the web server. A cookie (with the name fanws) is used to track which session is made available to the request.

All values stored in the session must be either immutable or serialisable. Note that immutable objects give better performance.

For scalable applications, the session should be used sparingly; house cleaned regularly and not used as a dumping ground.

Flash

Whereas normal session values are persisted indefinitely, flash vales only exist until the end of the next request. After that, they are removed from the session.

A common usage is to store message values before a redirect (usually after a form post). When the following page is rendered, the message is retrieved and displayed. After which the message is automatically discarded from the session.

(Flash: A-ah - Saviour of the Universe!)

containsKey

Source

abstract Bool containsKey(Str key)

Returns true if the session map contains the given key.

Calling this method does not create a session if it does not exist.

delete

Source

abstract Void delete()

Delete this web session which clears both the user agent cookie and the server side session instance. This method must be called before the WebRes is committed otherwise the server side instance is cleared, but the user agent cookie will remain uncleared.

Calling this method does not create a session if it does not exist.

@see web::WebSession.delete

exists

Source

abstract Bool exists()

Returns true if a session exists.

Calling this method does not create a session if it does not exist.

flash

Source

abstract Str:Obj? flash()

A map whose name/value pairs are persisted only until the end of the user's next HTTP request.

The returned map is READ ONLY.

flashRemove

Source

abstract Obj? flashRemove(Str key)

Removes the key/value pair from flash and returns the value. If the key was not mapped then returns null.

Calling this method does not create a session if it does not exist.

flashSet

Source

abstract Void flashSet(Str key, Obj? val)

Sets the given value in the flash. The key/value pair will be persisted until the end of the user's next request.

Values must be immutable or serialisable.

Calling this method will create a session if it does not exist.

get

Source

@Operator
abstract Obj? get(Str name, Obj? def := null)

Returns session value or def if not defined.

Calling this method does not create a session if it does not exist.

@see web::WebSession.get

getOrAdd

Source

abstract Obj? getOrAdd(Str key, |Str->Obj? valFunc)

Convenience for map.getOrAdd(name, valFunc).

Calling this will create a session if it doesn't already exist.

id

Source

abstract Str id()

Get the unique id used to identify this session.

Calling this method will create a session if it does not exist.

@see web::WebSession.id

isEmpty

Source

abstract Bool isEmpty()

Returns true if the session map is empty.

Calling this method does not create a session if it does not exist.

map

Source

abstract Str:Obj? map()

The application name/value pairs which are persisted between HTTP requests. Returns an empty map if a session does not exist.

Calling this method does not create a session if it does not exist.

The returned map is READ ONLY.

onCreate

Source

abstract Void onCreate(|HttpSession fn)

Adds an event handler that gets called as soon as a session is created.

Callbacks may be mutable, do not need to be cleaned up, but should be added at the start of every HTTP request.

remove

Source

abstract Void remove(Str name)

Convenience for map.remove(name).

Calling this method does not create a session if it does not exist.

@see web::WebSession.remove

set

Source

@Operator
abstract Void set(Str name, Obj? val)

Sets a session value - which must be immutable or serialisable.

Calling this method will create a session if it does not exist.

@see web::WebSession.set