memcached_backend#

class starlite.middleware.session.memcached_backend.MemcachedBackend#

Bases: ServerSideBackend[MemcachedBackendConfig]

Session backend to store data in memcached.

__init__(config: MemcachedBackendConfig) None#

Initialize MemcachedBackend

Parameters:

config – A MemcachedBackendConfig instance

Notes

  • Requires aiomcache. Install with pip install starlite[memcached]

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

Retrieve data associated with session_id from memcached.

Parameters:

session_id – The session-ID

Returns:

The session data, if existing, otherwise None.

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

Store data in memcached under <prefix>:<session_id>. 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. Fail silently if no such session-ID exists.

Parameters:

session_id – The session-ID

Returns:

None

delete_all() None#

Delete all data stored within this backend.

Returns:

None

Notes

This has poor performance since memcached does not offer utilities to properly scan or match keys by prefix.

Deprecated since version 1.43.0: This method is deprecated since 1.43.0. If you need this functionality, consider using the redis backend instead.

class starlite.middleware.session.memcached_backend.MemcachedBackendConfig#

Bases: ServerSideSessionConfig

Configuration for MemcachedBackend

memcached: Client#

An aiomcache.Client instance.

key_prefix: str#

Prefix to store data under after the schema of <prefix>:<session-ID>