{"record":{"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":"warning","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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Cache/DynamoDbStore.php#L501-L537","documentation":"DynamoDbStore::flush is intentionally unsupported. DynamoDB's Scan + DeleteItem pattern to empty a table is prohibitively expensive and slow at scale, so Laravel refuses to perform it. The method is typed 'never' — it always throws. The documented alternative is to delete and recreate the DynamoDB table.","triggerScenarios":"Calling Cache::store('dynamodb')->flush(), Cache::flush() when the default driver is dynamodb, or running php artisan cache:clear with CACHE_DRIVER=dynamodb. Also Artisan tinker experiments calling flush().","commonSituations":"CI test setup calling Cache::flush() between tests with dynamodb driver. Migration/deploy scripts that flush cache as a cleanup step. Local dev with dynamodb-local driver forgets this constraint.","solutions":["Replace flush() calls with Cache::forget($key) for specific keys, or use tagged cache with Cache::tags(['group'])->flush() (note: DynamoDB tag support is limited).","Recreate the table: drop it via AWS SDK / IaC (Terraform/CloudFormation) and recreate, then point CACHE_STORE at the new table.","Use a prefix strategy: instead of flushing, change CACHE_PREFIX between deployments to logically invalidate all keys without deleting.","Switch to a flushable driver (redis, database) for cache entries that require periodic full flush."],"exampleFix":"// before\nCache::store('dynamodb')->flush(); // RuntimeException always\n\n// after - use prefix rotation\n$newPrefix = 'app-' . now()->timestamp;\nconfig(['cache.prefix' => $newPrefix]);\n// or per-key invalidation\nforeach ($keysToInvalidate as $key) {\n    Cache::forget($key);\n}","handlingStrategy":"fallback","validationCode":"// Detect DynamoDB driver and avoid flush()\nif (Cache::store('dynamodb')->getStore() instanceof \\Illuminate\\Cache\\DynamoDbStore) {\n    // cannot flush; use prefix rotation or per-key forget\n    return;\n}\nCache::flush();","typeGuard":"function storeSupportsFlush(\\Illuminate\\Contracts\\Cache\\Store $store): bool\n{\n    // DynamoDbStore::flush always throws\n    return ! ($store instanceof \\Illuminate\\Cache\\DynamoDbStore);\n}","tryCatchPattern":"try {\n    Cache::flush();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'DynamoDb does not support flushing')) {\n        // rotate prefix instead\n        config(['cache.prefix' => 'app-' . dechex(time())]);\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Design cache invalidation around key/prefix rotation rather than full flush when using DynamoDB.","Gate Cache::flush() behind a driver check; provide a project helper cacheClear() that branches by driver.","In CI, replace Cache::flush() with Cache::forget() per test key when using dynamodb-local.","Document the DynamoDB flush limitation in the team's cache usage guide."],"tags":["cache","dynamodb","aws","unsupported-operation"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}