Implement a file based session store.
Attributes
| Attribute | Type | Description |
|---|
| storage_path | string | The absolute directory path where session files are stored, determined by the SESSION_FILE_PATH setting or the system temporary directory. |
| file_prefix | string | A 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
| Name | Type | Description |
|---|
| session_key | string = None | The 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
| Type | Description |
|---|
dict | The 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
| Type | Description |
|---|
dict | The decoded session data dictionary |
create()
@classmethod
def create() - > null
Generates a new unique session key and creates an initial session file on disk.
Returns
acreate()
@classmethod
def acreate() - > null
Asynchronously generates a new unique session key and creates an initial session file.
Returns
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
| Name | Type | Description |
|---|
| must_create | boolean = False | If True, raises a CreateError if the session file already exists; if False, raises an UpdateError if it does not exist |
Returns
asave()
@classmethod
def asave(
must_create: boolean = False
) - > null
Asynchronously saves the current session data to a file.
Parameters
| Name | Type | Description |
|---|
| must_create | boolean = False | Flag to enforce creation of a new file or update of an existing one |
Returns
exists()
@classmethod
def exists(
session_key: string
) - > boolean
Checks if a session file exists on disk for the provided session key.
Parameters
| Name | Type | Description |
|---|
| session_key | string | The session identifier to verify |
Returns
| Type | Description |
|---|
boolean | True 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
| Name | Type | Description |
|---|
| session_key | string | The session identifier to verify |
Returns
| Type | Description |
|---|
boolean | True 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
| Name | Type | Description |
|---|
| session_key | string = null | The identifier of the session to delete; defaults to the current session |
Returns
adelete()
@classmethod
def adelete(
session_key: string = null
) - > null
Asynchronously removes the session file from the storage directory.
Parameters
| Name | Type | Description |
|---|
| session_key | string = null | The identifier of the session to delete |
Returns
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
aclear_expired()
@classmethod
def aclear_expired() - > null
Asynchronously removes all expired session files from the storage directory.
Returns