BaseSessionManager
This class provides a base manager for handling session data persistence and serialization. It facilitates the encoding of session dictionaries into strings and manages the lifecycle of session objects by saving or deleting them based on their content. The manager relies on the associated model's session store class to perform the underlying data encoding.
Methods
encode()
@classmethod
def encode(
session_dict: dict
) - > string
Return the given session dictionary serialized and encoded as a string.
Parameters
| Name | Type | Description |
|---|---|---|
| session_dict | dict | The dictionary containing session keys and values to be serialized. |
Returns
| Type | Description |
|---|---|
string | The serialized and encoded session data string used for storage. |
save()
@classmethod
def save(
session_key: string,
session_dict: dict,
expire_date: datetime
) - > object
Persists the session data to the database or deletes the session record if the provided dictionary is empty.
Parameters
| Name | Type | Description |
|---|---|---|
| session_key | string | The unique identifier for the session. |
| session_dict | dict | The session data to be stored; if empty, the session record is deleted from the database. |
| expire_date | datetime | The timestamp indicating when the session should expire. |
Returns
| Type | Description |
|---|---|
object | The session model instance that was either saved or deleted. |