memory_backend#

class starlite.middleware.session.memory_backend.MemoryBackend#

Bases: ServerSideBackend[MemoryBackendConfig]

Session backend to store data in memory.

__init__(config: MemoryBackendConfig) None#

Initialize MemoryBackend.

Parameters:

config – An instance of MemoryBackendConfig

Warning

This should not be used in production and serves mainly as a dummy backend for easy testing. It is not process-safe, and data won’t be persisted

async get(session_id: str) Optional[bytes]#

Retrieve data associated with session_id.

Parameters:

session_id – The session-ID

Returns:

The session data, if existing, otherwise None.

async set(session_id: str, data: bytes) None#

Store data under the session_id for later retrieval.

If there is already data associated with session_id, replace it with data and reset its expiry time

Parameters:
  • session_id – The session-ID

  • data – Serialized session data

Returns:

None

async delete(session_id: str) None#

Delete the data associated with session_id. Fails silently if no such session-ID exists.

Parameters:

session_id – The session-ID

Returns:

None

async delete_all() None#

Delete all session data.

Returns:

None

class starlite.middleware.session.memory_backend.MemoryBackendConfig#

Bases: ServerSideSessionConfig

Configuration for MemoryBackend