From 68b9c615a862bde9391847991d3352154e5b072d Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Mon, 10 Jul 2023 10:33:19 +0200 Subject: [PATCH] Fix the dynamodb store (#1515) * Fix the dynamodb store * Throw an exception when attempting to flush the dynamo store * Normalize the composer constraint --- composer.json | 2 +- phpstan.neon.dist | 1 - psalm.baseline.xml | 8 ---- .../Cache/src/AsyncAwsDynamoDbStore.php | 38 +------------------ 4 files changed, 2 insertions(+), 47 deletions(-) diff --git a/composer.json b/composer.json index e745eb089..7177664f3 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "symfony/service-contracts": "^1.0 || ^2.0 || ^3.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "3.17.*", + "friendsofphp/php-cs-fixer": "~3.17.0", "illuminate/cache": "^6.18.13 || ^7.10 || ^8.0 || ^9.0", "illuminate/filesystem": "^6.18.13 || ^7.10 || ^8.0", "illuminate/mail": "^6.18.13 || ^7.10 || ^8.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bdf5a7246..d2b070372 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -15,6 +15,5 @@ parameters: - src/Integration/Laravel/Filesystem/src/AsyncAwsFilesystemAdapter.php ignoreErrors: - - '#^Parameter \#1 \$input of method AsyncAws\\DynamoDb\\DynamoDbClient::\w+\(\) expects array\{[^\)]+\}\|AsyncAws\\DynamoDb\\Input\\\w+Input, array\{[^\)]+\} given\.#' - '#PHPDoc tag @throws with type Psr\\Cache\\CacheException is not subtype of Throwable$#' - '#^Dead catch - JsonException is never thrown in the try block\.$#' diff --git a/psalm.baseline.xml b/psalm.baseline.xml index e38d098fa..d16b49bb0 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -68,14 +68,6 @@ - - $this->table, - 'KeySchema' => [ - new KeySchemaElement(['AttributeName' => 'key', 'KeyType' => KeyType::HASH]), - ], - ]]]> - getCode()]]> diff --git a/src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php b/src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php index ca98e6b40..76ef2fe77 100755 --- a/src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php +++ b/src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php @@ -2,13 +2,10 @@ namespace AsyncAws\Illuminate\Cache; -use AsyncAws\Core\Exception\Http\HttpException; use AsyncAws\Core\Exception\RuntimeException; use AsyncAws\DynamoDb\DynamoDbClient; -use AsyncAws\DynamoDb\Enum\KeyType; use AsyncAws\DynamoDb\Exception\ConditionalCheckFailedException; use AsyncAws\DynamoDb\ValueObject\AttributeValue; -use AsyncAws\DynamoDb\ValueObject\KeySchemaElement; use Illuminate\Contracts\Cache\LockProvider; use Illuminate\Contracts\Cache\Store; use Illuminate\Support\Carbon; @@ -397,40 +394,7 @@ public function forget($key) */ public function flush() { - try { - // Delete the table - $this->dynamoDb->deleteTable(['TableName' => $this->table]); - } catch (HttpException $e) { - $code = (int) $e->getCode(); - if (404 !== $code) { - // Any error but "table not found" - throw new RuntimeException('Could not flush DynamoDb cache. Table could not be deleted.', $code, $e); - } - } - - // Wait until table is removed - $response = $this->dynamoDb->tableNotExists(['TableName' => $this->table]); - $response->wait(100, 3); - if (!$response->isSuccess()) { - throw new RuntimeException('Could not flush DynamoDb cache. Table could not be deleted.'); - } - - // Create a new table - $this->dynamoDb->createTable([ - 'TableName' => $this->table, - 'KeySchema' => [ - new KeySchemaElement(['AttributeName' => 'key', 'KeyType' => KeyType::HASH]), - ], - ]); - - // Wait until table is created - $response = $this->dynamoDb->tableExists(['TableName' => $this->table]); - $response->wait(100, 3); - if (!$response->isSuccess()) { - throw new RuntimeException('Could not flush DynamoDb cache. Table could not be created.'); - } - - return true; + throw new RuntimeException('DynamoDb does not support flushing an entire table. Please create a new table.'); } /**