|
Malloy
|
#include <session.hpp>

Public Types | |
| using | key_type = std::string |
| using | value_type = std::string |
| using | id_type = std::string |
Public Member Functions | |
| session (id_type &&id) | |
| virtual | ~session ()=default |
| session (const session &other)=delete | |
| session (session &&other) noexcept=delete | |
| session & | operator= (const session &other)=delete |
| session & | operator= (session &&other) noexcept=delete |
| bool | set (const key_type &key, value_type value) |
| std::optional< key_type > | get (const key_type &key) |
| virtual bool | remove (const key_type &key) |
| id_type | id () const noexcept |
| cookie | generate_cookie (std::string cookie_name) const |
Protected Member Functions | |
| virtual bool | storage_set (const key_type &key, value_type value)=0 |
| virtual std::optional< value_type > | storage_get (const key_type &key) const =0 |
| virtual bool | storage_remove (const key_type &key)=0 |
| virtual void | update_access_time ()=0 |
This class represents a session.
This is a classic implementation for achieving a stateful session over stateless HTTP. It works by generating a server-side session using an object of this class and sending the session ID to the client as a cookie. The client will send back this cookie on sub-sequent requests through which the server can retrieve the corresponding session ID.
|
inlineexplicit |
Constructor.
update_access_time() in their constructor.| id | The session ID. |
|
virtualdefault |
Destructor.
|
delete |
Copy constructor.
| other |
|
deletenoexcept |
Move constructor
| other |
|
inline |
Generates a session cookie for this session.
| cookie_name | The cookie name. |
|
inline |
Get the value of a particular key.
| key | The key. |

|
inlinenoexcept |
Get the session ID.
Copy assignment operator.
| other |
Move assignment operator.
| other |
|
inlinevirtual |
Remove a key-value pair.
| key | The key. |

|
inline |
Add or update a key-value pair.
If the specified key does not exist yet, a new key-value pair will be created. If the key exists, the current value will be updated.
| key | The key. |
| value | The value. |

|
protectedpure virtual |
Get the value of a particular key.
| key | The key. |
|
protectedpure virtual |
Remove a key-value pair.
| key | The key. |
|
protectedpure virtual |
Add or update a key-value pair.
If the specified key does not exist yet, a new key-value pair will be created. If the key exists, the current value will be updated.
| key | The key. |
| value | The value. |
|
protectedpure virtual |
Update the access time.
This should usually update the access time to the current time.
Implemented in malloy::http::sessions::session_chrono< Clock >, and malloy::http::sessions::session_chrono< std::chrono::steady_clock >.