dynamodb

Summary

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

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

Notes

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 (ResourceCreatorContext | None) – An existing ResourceCreatorContext to reuse instead of creating a new one

  • kwargs (Any) – Additional keyword arguments for CacheBackend or backend connection

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 (ResourceCreatorContext)

  • kwargs (Any)

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