dynamodb#
Summary#
|
|
|
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 usekey_attr_name (
str
) – The name of the field to use for keys in the DynamoDB documentval_attr_name (
str
) – The name of the field to use for values in the DynamoDB documentcreate_if_not_exists (
bool
) – Whether or not to attempt to create the DynamoDB tablecontext (
Optional
[ResourceCreatorContext
]) – An existing ResourceCreatorContext to reuse instead of creating a new oneexpire_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 aaiohttp.ClientResponse
object and returns a boolean indicating whether or not that response should be cached. Will be applied to both new and previously cached responsessecret_key (Iterable | str | bytes | None) – Optional secret key used to sign cache items for added security
serializer – Custom serializer that provides
loads
anddumps
methodsregion_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:
cache_name (
str
) –key_attr_name (
str
) –val_attr_name (
str
) –create_if_not_exists (
bool
) –context (
Optional
[ResourceCreatorContext
]) –kwargs (
Any
) –expire_after (None | int | float | str | datetime | timedelta) –
urls_expire_after (Dict[str, None | int | float | str | datetime | timedelta] | None) –
include_headers (bool) –
cache_control (bool) –
filter_fn (Callable[[
aiohttp.ClientResponse
| CachedResponse], bool] | Callable[[aiohttp.ClientResponse
| CachedResponse], Awaitable[bool]]) –region_name (str | None) –
api_version (str | None) –
use_ssl (bool) –
endpoint_url (str | None) –
aws_access_key_id (str | None) –
aws_secret_access_key (str | None) –
aws_session_token (str | None) –
config (Config) –
- 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:
- _abc_impl = <_abc_data object>#
- async _create_table(conn)#
- async _scan()#
- Return type:
- async bulk_delete(keys)#
Delete item(s) from the cache. Does not raise an error if the item is missing.
- async contains(key)#
Check if a key is stored in the cache
- async delete(key)#
Delete an item from the cache. Does not raise an error if the item is missing.
- get_connection()#
- async get_table()#
- async keys()#
Get all keys stored in the cache
- Return type:
- async read(key)#
Read an item from the cache. Returns
None
if the item is missing.
- async values()#
Get all values stored in the cache
- Return type: