{"id":"97b19867858573e9","repo":"laravel/framework","slug":"dynamodb-does-not-support-flushing-an-entire-table","errorCode":null,"errorMessage":"DynamoDb does not support flushing an entire table. Please create a new table.","messagePattern":"DynamoDb does not support flushing an entire table\\. Please create a new table\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Cache/DynamoDbStore.php","lineNumber":519,"sourceCode":"                $this->keyAttribute => [\n                    'S' => $this->prefix.$key,\n                ],\n            ],\n        ]);\n\n        return true;\n    }\n\n    /**\n     * Remove all items from the cache.\n     *\n     * @return never\n     *\n     * @throws \\RuntimeException\n     */\n    public function flush()\n    {\n        throw new RuntimeException('DynamoDb does not support flushing an entire table. Please create a new table.');\n    }\n\n    /**\n     * Get the UNIX timestamp for the given number of seconds.\n     *\n     * @param  int  $seconds\n     * @return int\n     */\n    protected function toTimestamp($seconds)\n    {\n        return $seconds > 0\n            ? $this->availableAt($seconds)\n            : $this->currentTime();\n    }\n\n    /**\n     * Serialize the value.\n     *","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/DynamoDbStore.php#L501-L537","documentation":"DynamoDbStore::flush() unconditionally throws RuntimeException because DynamoDB has no efficient 'delete all rows' operation and a Scan+Delete loop would be prohibitively expensive. The framework refuses to flush and instructs creating a new table instead.","triggerScenarios":"Calling Cache::store('dynamodb')->flush(), Artisan cache:clear resolving to a dynamodb store, or any reset/test teardown that invokes flush() on a DynamoDB-backed cache. The throw happens every time flush() is called regardless of contents.","commonSituations":"Running php artisan cache:clear in a test/staging environment whose CACHE_STORE=dynamodb. Sharing a DynamoDB table across environments and attempting to clear one. CI pipelines that flush caches between runs.","solutions":["Do not call flush() on DynamoDB stores; instead delete and recreate the table (CloudFormation/CDK/IaC) to reset.","For tests, use a separate DynamoDB table (or the array driver) and tear it down rather than flushing.","If selective clearing is needed, iterate keys and forget() each (Scan then batch DeleteItem).","Point CACHE_STORE at a non-dynamodb driver in environments that need flush() (e.g. testing)."],"exampleFix":"// before\nCache::store('dynamodb')->flush(); // always throws\n\n// after\n// Option A: drop & recreate the table via AWS CLI/IaC\naws dynamodb delete-table --table-name cache\naws dynamodb create-table ... # via CloudFormation\n\n// Option B: forget specific keys\nforeach ($keys as $k) {\n    Cache::store('dynamodb')->forget($k);\n}","handlingStrategy":"validation","validationCode":"if (Cache::store('dynamodb')->getStore() instanceof \\Illuminate\\Cache\\DynamoDbStore) {\n    throw new \\RuntimeException('Cannot flush DynamoDB cache; recreate the table instead.');\n}\nCache::flush();","typeGuard":"function cacheSupportsFlush(string $storeName): bool\n{\n    $store = Cache::store($storeName)->getStore();\n    return ! ($store instanceof \\Illuminate\\Cache\\DynamoDbStore);\n}","tryCatchPattern":"try {\n    Cache::store('dynamodb')->flush();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'DynamoDb does not support flushing')) {\n        // recreate table via IaC, or forget() individual keys\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Never call flush() on DynamoDB stores.","Use array/file drivers in tests to allow teardown.","Automate table recreation via CloudFormation/CDK.","Document DynamoDB cache limitations for ops."],"tags":["cache","dynamodb","aws","unsupported-operation"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}