Skip to main content

SessionStore

Implement cached, database backed sessions.

Attributes

AttributeTypeDescription
cache_key_prefixstring = KEY_PREFIXA 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

NameTypeDescription
session_keystring = NoneThe 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

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

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

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

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

NameTypeDescription
session_keystringThe unique session identifier to verify for existence.

Returns

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

NameTypeDescription
session_keystringThe unique session identifier to verify for existence.

Returns

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

NameTypeDescription
must_createboolean = FalseIf 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

NameTypeDescription
must_createboolean = FalseIf 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

NameTypeDescription
session_keystring = NoneThe 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

NameTypeDescription
session_keystring = NoneThe specific session identifier to delete; defaults to the current session key if not provided.

flush()

@classmethod
def flush()

Remove the current session data from the database and regenerate the key.


aflush()

@classmethod
def aflush()

See flush().