laravel/framework · warning · RuntimeException

DynamoDb does not support flushing an entire table. Please…

Error message

DynamoDb does not support flushing an entire table. Please create a new table.

What it means

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.

Solutions

  1. 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).
  2. Recreate the table: drop it via AWS SDK / IaC (Terraform/CloudFormation) and recreate, then point CACHE_STORE at the new table.
  3. Use a prefix strategy: instead of flushing, change CACHE_PREFIX between deployments to logically invalidate all keys without deleting.
  4. Switch to a flushable driver (redis, database) for cache entries that require periodic full flush.

Example fix

// before
Cache::store('dynamodb')->flush(); // RuntimeException always

// after - use prefix rotation
$newPrefix = 'app-' . now()->timestamp;
config(['cache.prefix' => $newPrefix]);
// or per-key invalidation
foreach ($keysToInvalidate as $key) {
    Cache::forget($key);
}
Defensive patterns

Strategy: fallback

Validate before calling

// Detect DynamoDB driver and avoid flush()
if (Cache::store('dynamodb')->getStore() instanceof \Illuminate\Cache\DynamoDbStore) {
    // cannot flush; use prefix rotation or per-key forget
    return;
}
Cache::flush();

Type guard

function storeSupportsFlush(\Illuminate\Contracts\Cache\Store $store): bool
{
    // DynamoDbStore::flush always throws
    return ! ($store instanceof \Illuminate\Cache\DynamoDbStore);
}

Try / catch

try {
    Cache::flush();
} catch (\RuntimeException $e) {
    if (str_contains($e->getMessage(), 'DynamoDb does not support flushing')) {
        // rotate prefix instead
        config(['cache.prefix' => 'app-' . dechex(time())]);
    } else {
        throw $e;
    }
}

Prevention

When it happens

Trigger: 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().

Common situations: 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.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/97b19867858573e9. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Cache/DynamoDbStore.php:519

                $this->keyAttribute => [
                    'S' => $this->prefix.$key,
                ],
            ],
        ]);

        return true;
    }

    /**
     * Remove all items from the cache.
     *
     * @return never
     *
     * @throws \RuntimeException
     */
    public function flush()
    {
        throw new RuntimeException('DynamoDb does not support flushing an entire table. Please create a new table.');
    }

    /**
     * Get the UNIX timestamp for the given number of seconds.
     *
     * @param  int  $seconds
     * @return int
     */
    protected function toTimestamp($seconds)
    {
        return $seconds > 0
            ? $this->availableAt($seconds)
            : $this->currentTime();
    }

    /**
     * Serialize the value.
     *

View on GitHub (pinned to e0f6eb3518)