dynamodb#

Summary#

DynamoDBBackend([cache_name, key_attr_name, ...])

Async cache backend for DynamoDB (requires aioboto3)

DynamoDbCache(table_name, namespace[, ...])

An async interface for caching objects in a DynamoDB key-store

Module Contents#

class DynamoDBBackend(cache_name='aiohttp-cache', key_attr_name='k', val_attr_name='v', create_if_not_exists=False, context=None, **kwargs)#

Bases: CacheBackend

Async cache backend for DynamoDB (requires aioboto3)

See DynamoDB Service Resource for more usage details.

__init__(cache_name='aiohttp-cache', key_attr_name='k', val_attr_name='v', create_if_not_exists=False, context=None, **kwargs)#
Parameters:
  • cache_name (str) – Table name to use

  • key_attr_name (str) – The name of the field to use for keys in the DynamoDB document

  • val_attr_name (str) – The name of the field to use for values in the DynamoDB document

  • create_if_not_exists (bool) – Whether or not to attempt to create the DynamoDB table

  • context (Optional[ResourceCreatorContext]) – An existing ResourceCreatorContext to reuse instead of creating a new one

  • expire_after (None | int | float | str | datetime | timedelta) – Time after which a cache entry will be expired; see Cache Expiration for possible formats

  • urls_expire_after (Dict[str, None | int | float | str | datetime | timedelta] | None) – Expiration times to apply for different URL patterns

  • allowed_codes (Tuple[int, ...]) – Only cache responses with these status codes

  • allowed_methods (Tuple[str, ...]) – Only cache requests with these HTTP methods

  • include_headers (bool) – Cache requests with different headers separately

  • ignored_params (Iterable[str] | None) – Request parameters to be excluded from the cache key

  • cache_control (bool) – Use Cache-Control response headers

  • filter_fn (Callable[[aiohttp.ClientResponse | CachedResponse], bool] | Callable[[aiohttp.ClientResponse | CachedResponse], Awaitable[bool]]) – function that takes a aiohttp.ClientResponse object and returns a boolean indicating whether or not that response should be cached. Will be applied to both new and previously cached responses

  • secret_key (Iterable | str | bytes | None) – Optional secret key used to sign cache items for added security

  • salt (str | bytes) – Optional salt used to sign cache items

  • serializer – Custom serializer that provides loads and dumps methods

  • region_name (str | None) – The name of the region associated with the client.

  • api_version (str | None) – A previous API version to use instead of the latest version

  • use_ssl (bool) – Whether or not to use SSL. Note that not all services support non-ssl connections.

  • verify (bool | str) – Whether or not to verify SSL certificates. You may provide either False or a path to the CA cert bundle to use.

  • endpoint_url (str | None) – The complete URL to use for the constructed client. If this value is provided, then use_ssl is ignored.

  • aws_access_key_id (str | None) – The access key to use when creating the client.

  • aws_secret_access_key (str | None) – The secret key to use when creating the client.

  • aws_session_token (str | None) – The session token to use when creating the client.

  • config (Config) – Advanced client configuration options. See botocore config documentation for more details.

  • kwargs (Any) –

Parameters:
class DynamoDbCache(table_name, namespace, key_attr_name='k', val_attr_name='v', create_if_not_exists=False, context=None, **kwargs)#

Bases: BaseCache

An async interface for caching objects in a DynamoDB key-store

The actual key name on the dynamodb server will be namespace:key. In order to deal with how dynamodb stores data/keys, all values must be serialized.

Parameters:
  • table_name (str) –

  • namespace (str) –

  • key_attr_name (str) –

  • val_attr_name (str) –

  • create_if_not_exists (bool) –

  • context (Optional[ResourceCreatorContext]) –

  • kwargs (Any) –

_abc_impl = <_abc_data object>#
async _create_table(conn)#
_doc(key)#
Return type:

Dict

async _scan()#
Return type:

AsyncIterable[Dict]

async bulk_delete(keys)#

Delete item(s) from the cache. Does not raise an error if the item is missing.

Parameters:

keys (set) –

Return type:

None

async clear()#

Delete all items from the cache

Return type:

None

async contains(key)#

Check if a key is stored in the cache

Parameters:

key (str) –

Return type:

bool

async delete(key)#

Delete an item from the cache. Does not raise an error if the item is missing.

Parameters:

key (str) –

Return type:

None

get_connection()#
async get_table()#
async keys()#

Get all keys stored in the cache

Return type:

AsyncIterable[str]

async read(key)#

Read an item from the cache. Returns None if the item is missing.

Parameters:

key (str) –

Return type:

Union[CachedResponse, bytes, str, None]

async size()#

Get the number of items in the cache

Return type:

int

async values()#

Get all values stored in the cache

Return type:

AsyncIterable[Union[CachedResponse, bytes, str, None]]

async write(key, item)#

Write an item to the cache

Parameters:
Return type:

None