memcached_cache_backend#

class starlite.cache.memcached_cache_backend.MemcachedCacheBackendConfig#

Bases: BaseModel

Memcached cache backend configuration.

host: str#

Memcached host.

port: Optional[int]#

memcached port (optional, defaults to 11211)

pool_size: Optional[int]#

Maximum number of memcached open connections (optional, defaults to 2)

pool_minsize: Optional[int]#

memcached minimum pool size (optional, by default set to pool_size)

serialize: Callable[[Any], bytes]#

A callable to serialize data that goes into the cache from an object to bytes, defaults to pickle.dumps

deserialize: Callable[[bytes], Any]#

A callable to deserialize data coming from the cache from bytes to an object, defaults to pickle.loads

class starlite.cache.memcached_cache_backend.MemcachedCacheBackend#

Bases: CacheBackendProtocol

Memcached-based cache backend.

__init__(config: MemcachedCacheBackendConfig) None#

Initialize MemcachedCacheBackend.

Parameters:

config – required configuration to connect to memcached.

async get(key: str) Any#

Retrieve a value from cache corresponding to the given key.

Parameters:

key – name of cached value.

Returns:

Cached value if existing else None.

async set(key: str, value: Any, expiration: int) None#

Set sa value in cache for a given key for a duration determined by expiration.

Parameters:
  • key – key to cache value under.

  • value – the value to be cached.

  • expiration – expiration of cached value in seconds.

Notes

  • expiration is in seconds.

  • return value is not used by Starlite internally.

Returns:

None

async delete(key: str) None#

Delete a value from the cache and remove the given key.

Parameters:

key – key to be deleted from the cache.

Notes

  • return value is not used by Starlite internally.

Returns:

None