From dc74f212ebaffdb183eb54e55a5d51e1271c671b Mon Sep 17 00:00:00 2001 From: Jordan Cook Date: Tue, 28 Feb 2023 13:09:49 -0600 Subject: Update docs and screenshots for DynamoDB --- HISTORY.md | 6 +++++- docs/_static/dynamodb_create_table.png | Bin 0 -> 51196 bytes docs/_static/dynamodb_items.png | Bin 69437 -> 37675 bytes docs/_static/dynamodb_response.png | Bin 124237 -> 102427 bytes docs/user_guide/backends/dynamodb.md | 25 +++++++++++++++++++------ examples/cloudformation.yml | 6 +----- 6 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 docs/_static/dynamodb_create_table.png diff --git a/HISTORY.md b/HISTORY.md index 09b6c1b..6ffdfbe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -31,6 +31,10 @@ 💾 **Backends:** * **DynamoDB**: + * For better read performance and usage of read throughput: + * The cache key is now used as the partition key + * Redirects are now cached only in-memory and not persisted + * Cache size (`len()`) now uses a fast table estimate instead of a full scan * Store responses in plain (human-readable) document format instead of fully serialized binary * Create default table in on-demand mode instead of provisioned * Add optional integration with DynamoDB TTL to improve performance for removing expired responses @@ -132,7 +136,6 @@ replacements are listed below. If this causes problems for you, please open an i ⚠️ **Breaking changes:** -Some breaking changes have been made that are not expected to affect most users. If you encounter a problem not listed here after updating to 1.0, please create a bug report! * The `BaseCache.urls` property has been replaced with a method that returns a list of URLs @@ -141,6 +144,7 @@ If you encounter a problem not listed here after updating to 1.0, please create * The `CachedSession` `backend` argument must be either an instance or string alias. Previously it would also accept a backend class. * After initialization, cache settings can only be accesed and modified via `CachedSession.settings`. Previously, some settings could be modified by setting them on either `CachedSession` or `BaseCache`. In some cases this could silently fail or otherwise have undefined behavior. +* DynamoDB table structure has changed. If you are using DynamoDB, you will need to create a new table when upgrading to 1.0. See [DynamoDB backend docs](https://requests-cache.readthedocs.io/en/stable/user_guide/backends/dynamodb.html#dynamodb) for more details. * The following is relevant for **custom backends** that extend built-in storage classes: * All serializer-specific `BaseStorage` subclasses have been removed, and merged into their respective parent classes. This includes `SQLitePickleDict`, `MongoPickleDict`, and `GridFSPickleDict`. * All `BaseStorage` subclasses now have a `serializer` attribute, which will be unused if diff --git a/docs/_static/dynamodb_create_table.png b/docs/_static/dynamodb_create_table.png new file mode 100644 index 0000000..0fcb7a0 Binary files /dev/null and b/docs/_static/dynamodb_create_table.png differ diff --git a/docs/_static/dynamodb_items.png b/docs/_static/dynamodb_items.png index 3ab4531..68066d0 100644 Binary files a/docs/_static/dynamodb_items.png and b/docs/_static/dynamodb_items.png differ diff --git a/docs/_static/dynamodb_response.png b/docs/_static/dynamodb_response.png index 9e2bae0..e0f4d85 100644 Binary files a/docs/_static/dynamodb_response.png and b/docs/_static/dynamodb_response.png differ diff --git a/docs/user_guide/backends/dynamodb.md b/docs/user_guide/backends/dynamodb.md index 7761903..85192ac 100644 --- a/docs/user_guide/backends/dynamodb.md +++ b/docs/user_guide/backends/dynamodb.md @@ -61,7 +61,12 @@ And here is an example response: ``` ::: -It is also possible query these responses with the [AWS CLI](https://aws.amazon.com/cli), for example: +It is also possible query these responses with the [AWS CLI](https://aws.amazon.com/cli), for +example: +```bash +aws dynamodb query --table-name http_cache > responses.json +``` + ```bash aws dynamodb query \ --table-name http_cache \ @@ -91,15 +96,23 @@ want to quickly test out DynamoDB as a cache backend, but in a production enviro likely want to create the tables yourself, for example with [CloudFormation](https://aws.amazon.com/cloudformation/) or [Terraform](https://www.terraform.io/). -Here are the details you will need: - +You just need a table with a single partition key. A `value` attribute (containing response data) +will be created dynamically once items are added to the table. - Table: `http_cache` (or any other name, as long as it matches the `table_name` parameter for `DynamoDbCache`) - Attributes: - - `namespace`: String - `key`: String - Keys: - - Partition key (aka namespace): `namespace` - - Range key (aka sort key): `key` + - Partition key (aka hash key): `key` + +Example of manually creating a table in the console: +:::{dropdown} Screenshot +:animate: fade-in-slide-down +:color: primary +:icon: file-media + +```{image} ../../_static/dynamodb_create_table.png +``` +::: ### Example CloudFormation Template :::{dropdown} Example diff --git a/examples/cloudformation.yml b/examples/cloudformation.yml index e88e0ab..fa83091 100644 --- a/examples/cloudformation.yml +++ b/examples/cloudformation.yml @@ -15,15 +15,11 @@ Resources: Properties: TableName: !Ref CacheTableName AttributeDefinitions: - - AttributeName: namespace - AttributeType: S - AttributeName: key AttributeType: S KeySchema: - - AttributeName: namespace - KeyType: HASH - AttributeName: key - KeyType: RANGE + KeyType: HASH # BillingMode: PAY_PER_REQUEST # Optional: Use provisioned throughput instead of on-demand -- cgit v1.2.1