Skip to content

Commit

Permalink
Fix the dynamodb store (#1515)
Browse files Browse the repository at this point in the history
* Fix the dynamodb store

* Throw an exception when attempting to flush the dynamo store

* Normalize the composer constraint
  • Loading branch information
stof authored Jul 10, 2023
1 parent 78eeca6 commit 68b9c61
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 47 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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\.$#'
8 changes: 0 additions & 8 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@
</InvalidArgument>
</file>
<file src="src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php">
<InvalidArgument>
<code><![CDATA[[
'TableName' => $this->table,
'KeySchema' => [
new KeySchemaElement(['AttributeName' => 'key', 'KeyType' => KeyType::HASH]),
],
]]]></code>
</InvalidArgument>
<RedundantCast>
<code><![CDATA[(int) $e->getCode()]]></code>
</RedundantCast>
Expand Down
38 changes: 1 addition & 37 deletions src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
}

/**
Expand Down

0 comments on commit 68b9c61

Please sign in to comment.