Skip to main content

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

NameTypeDescription
session_dictdictThe dictionary containing session keys and values to be serialized.

Returns

TypeDescription
stringThe 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

NameTypeDescription
session_keystringThe unique identifier for the session.
session_dictdictThe session data to be stored; if empty, the session record is deleted from the database.
expire_datedatetimeThe timestamp indicating when the session should expire.

Returns

TypeDescription
objectThe session model instance that was either saved or deleted.