Skip to main content

SessionStore

Implement a file based session store.

Attributes

AttributeTypeDescription
storage_pathstringThe absolute directory path where session files are stored, determined by the SESSION_FILE_PATH setting or the system temporary directory.
file_prefixstringA string prefix derived from the SESSION_COOKIE_NAME setting used to identify and namespace session files within the storage directory.

Constructor

Signature

def SessionStore(
session_key: string = None
) - > null

Parameters

NameTypeDescription
session_keystring = NoneThe unique identifier for the session.

Methods


load()

@classmethod
def load() - > dict

Loads the session data from the file system, handling decoding and automatic cleanup of expired sessions.

Returns

TypeDescription
dictThe decoded session data dictionary, or an empty dictionary if the file is missing or expired

aload()

@classmethod
def aload() - > dict

Asynchronously loads the session data from the file system.

Returns

TypeDescription
dictThe decoded session data dictionary

create()

@classmethod
def create() - > null

Generates a new unique session key and creates an initial session file on disk.

Returns

TypeDescription
null

acreate()

@classmethod
def acreate() - > null

Asynchronously generates a new unique session key and creates an initial session file.

Returns

TypeDescription
null

save()

@classmethod
def save(
must_create: boolean = False
) - > null

Saves the current session data to a file using an atomic write-and-rename strategy to prevent data corruption.

Parameters

NameTypeDescription
must_createboolean = FalseIf True, raises a CreateError if the session file already exists; if False, raises an UpdateError if it does not exist

Returns

TypeDescription
null

asave()

@classmethod
def asave(
must_create: boolean = False
) - > null

Asynchronously saves the current session data to a file.

Parameters

NameTypeDescription
must_createboolean = FalseFlag to enforce creation of a new file or update of an existing one

Returns

TypeDescription
null

exists()

@classmethod
def exists(
session_key: string
) - > boolean

Checks if a session file exists on disk for the provided session key.

Parameters

NameTypeDescription
session_keystringThe session identifier to verify

Returns

TypeDescription
booleanTrue if the session file exists, False otherwise

aexists()

@classmethod
def aexists(
session_key: string
) - > boolean

Asynchronously checks if a session file exists on disk.

Parameters

NameTypeDescription
session_keystringThe session identifier to verify

Returns

TypeDescription
booleanTrue if the session file exists, False otherwise

delete()

@classmethod
def delete(
session_key: string = null
) - > null

Removes the session file from the storage directory for the specified or current session key.

Parameters

NameTypeDescription
session_keystring = nullThe identifier of the session to delete; defaults to the current session

Returns

TypeDescription
null

adelete()

@classmethod
def adelete(
session_key: string = null
) - > null

Asynchronously removes the session file from the storage directory.

Parameters

NameTypeDescription
session_keystring = nullThe identifier of the session to delete

Returns

TypeDescription
null

clear_expired()

@classmethod
def clear_expired() - > null

Iterates through all session files in the storage path and deletes those that have passed their expiration date.

Returns

TypeDescription
null

aclear_expired()

@classmethod
def aclear_expired() - > null

Asynchronously removes all expired session files from the storage directory.

Returns

TypeDescription
null