Implement cached, database backed sessions.
Attributes
| Attribute | Type | Description |
|---|
| cache_key_prefix | string = KEY_PREFIX | A string prefix prepended to the session key to form the unique identifier used for storing and retrieving session data in the cache backend. |
Constructor
Signature
def SessionStore(
session_key: string = None
)
Parameters
| Name | Type | Description |
|---|
| session_key | string = None | The unique identifier for the session. |
Methods
cache_key()
@classmethod
def cache_key() - > string
Constructs the unique cache identifier by combining the prefix with the current session key.
Returns
| Type | Description |
|---|
string | The full cache key string used for storing session data in the cache backend. |
acache_key()
@classmethod
def acache_key() - > string
Asynchronously constructs the unique cache identifier by combining the prefix with the current session key.
Returns
| Type | Description |
|---|
string | The full cache key string used for storing session data in the cache backend. |
load()
@classmethod
def load() - > dict
Retrieves session data from the cache or falls back to the database if the cache is empty or fails.
Returns
| Type | Description |
|---|
dict | A dictionary containing the decoded session data. |
aload()
@classmethod
def aload() - > dict
Asynchronously retrieves session data from the cache or falls back to the database if the cache is empty or fails.
Returns
| Type | Description |
|---|
dict | A dictionary containing the decoded session data. |
exists()
@classmethod
def exists(
session_key: string
) - > boolean
Checks if a session key exists in either the cache or the database.
Parameters
| Name | Type | Description |
|---|
| session_key | string | The unique session identifier to verify for existence. |
Returns
| Type | Description |
|---|
boolean | True if the session key is found in the cache or database, False otherwise. |
aexists()
@classmethod
def aexists(
session_key: string
) - > boolean
Asynchronously checks if a session key exists in either the cache or the database.
Parameters
| Name | Type | Description |
|---|
| session_key | string | The unique session identifier to verify for existence. |
Returns
| Type | Description |
|---|
boolean | True if the session key is found in the cache or database, False otherwise. |
save()
@classmethod
def save(
must_create: boolean = False
)
Persists the session data to both the database and the cache backend.
Parameters
| Name | Type | Description |
|---|
| must_create | boolean = False | If True, ensures a new session is created and raises an error if the key already exists. |
asave()
@classmethod
def asave(
must_create: boolean = False
)
Asynchronously persists the session data to both the database and the cache backend.
Parameters
| Name | Type | Description |
|---|
| must_create | boolean = False | If True, ensures a new session is created and raises an error if the key already exists. |
delete()
@classmethod
def delete(
session_key: string = None
)
Removes the session data from both the database and the cache for the specified or current session key.
Parameters
| Name | Type | Description |
|---|
| session_key | string = None | The specific session identifier to delete; defaults to the current session key if not provided. |
adelete()
@classmethod
def adelete(
session_key: string = None
)
Asynchronously removes the session data from both the database and the cache for the specified or current session key.
Parameters
| Name | Type | Description |
|---|
| session_key | string = None | The specific session identifier to delete; defaults to the current session key if not provided. |
flush()
Remove the current session data from the database and regenerate the key.
aflush()
See flush().