Files
michaelschiemer/tests/debug/clear-discovery-cache.php
Michael Schiemer 03e5188644 Fix Discovery system context-dependent caching issue
The Discovery system was creating separate caches for WEB vs CLI contexts,
causing RequestFactory #[Initializer] to be missing in WEB context and
leading to 500 errors due to Request interface binding failures.

Changes:
- Remove execution context from Discovery cache keys
- Ensure consistent Discovery results across WEB and CLI contexts
- WEB and CLI now share same Discovery cache (535 items vs 369/535 split)
- RequestFactory consistently discovered in both contexts

Root cause: Context-dependent cache keys caused:
- CLI: discovery:full_{hash}_cli-script
- WEB: discovery:full_{hash}_web

Fixed: Both contexts now use discovery:full_{hash}

Resolves: #21 DI Container Request Interface Binding
Resolves: #18 Discovery WEB vs CLI Context differences
2025-09-13 00:36:07 +02:00

46 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
echo "=== Clearing Discovery Cache ===\n";
$cacheDir = __DIR__ . '/../../storage/cache';
if (!is_dir($cacheDir)) {
echo "Cache directory does not exist: $cacheDir\n";
exit(0);
}
// Find all cache files that might be related to discovery
$patterns = [
$cacheDir . '/discovery*',
$cacheDir . '/*discovery*',
$cacheDir . '/routes*',
$cacheDir . '/attr*'
];
$deletedCount = 0;
$totalSize = 0;
foreach ($patterns as $pattern) {
$files = glob($pattern);
foreach ($files as $file) {
if (is_file($file)) {
$size = filesize($file);
if (unlink($file)) {
echo "Deleted: " . basename($file) . " (" . number_format($size) . " bytes)\n";
$deletedCount++;
$totalSize += $size;
} else {
echo "Failed to delete: " . basename($file) . "\n";
}
}
}
}
if ($deletedCount === 0) {
echo "No cache files found to delete.\n";
} else {
echo "\nDeleted $deletedCount files, freed " . number_format($totalSize) . " bytes.\n";
}
echo "Cache clearing complete.\n";