82 lines
2.1 KiB
PHP
82 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\Cache\Driver\FileCache;
|
|
use App\Framework\Cache\GeneralCache;
|
|
use App\Framework\Serializer\Php\PhpSerializer;
|
|
use App\Framework\Cache\Warming\Strategies\CriticalPathWarmingStrategy;
|
|
use App\Framework\Router\CompiledRoutes;
|
|
use App\Framework\Config\Environment;
|
|
|
|
echo "🔍 Testing Cache Warming System\n\n";
|
|
|
|
// Setup
|
|
$fileCache = new FileCache();
|
|
$serializer = new PhpSerializer();
|
|
$cache = new GeneralCache($fileCache, $serializer);
|
|
|
|
$compiledRoutes = new CompiledRoutes(
|
|
staticRoutes: [
|
|
'GET' => [
|
|
'default' => [
|
|
'/home' => null,
|
|
'/about' => null,
|
|
]
|
|
]
|
|
],
|
|
dynamicPatterns: [
|
|
'GET' => [
|
|
'default' => null
|
|
]
|
|
],
|
|
namedRoutes: []
|
|
);
|
|
|
|
$environment = new Environment([
|
|
'APP_ENV' => 'testing',
|
|
'APP_DEBUG' => 'true',
|
|
]);
|
|
|
|
echo "✅ Created Cache, CompiledRoutes, Environment\n\n";
|
|
|
|
// Create strategy
|
|
$strategy = new CriticalPathWarmingStrategy(
|
|
cache: $cache,
|
|
compiledRoutes: $compiledRoutes,
|
|
environment: $environment
|
|
);
|
|
|
|
echo "✅ Created CriticalPathWarmingStrategy\n";
|
|
echo " Name: " . $strategy->getName() . "\n";
|
|
echo " Priority: " . $strategy->getPriority() . "\n";
|
|
echo " Should Run: " . ($strategy->shouldRun() ? 'yes' : 'no') . "\n";
|
|
echo " Estimated Duration: " . $strategy->getEstimatedDuration() . "s\n\n";
|
|
|
|
// Execute warmup
|
|
echo "🔥 Executing warmup...\n";
|
|
$result = $strategy->warmup();
|
|
|
|
echo "\n📊 Results:\n";
|
|
echo " Strategy: " . $result->strategyName . "\n";
|
|
echo " Items Warmed: " . $result->itemsWarmed . "\n";
|
|
echo " Items Failed: " . $result->itemsFailed . "\n";
|
|
echo " Duration: " . $result->durationSeconds . "s\n";
|
|
echo " Memory Used: " . $result->memoryUsedBytes . " bytes\n";
|
|
|
|
if (!empty($result->errors)) {
|
|
echo "\n❌ Errors:\n";
|
|
foreach ($result->errors as $error) {
|
|
print_r($error);
|
|
}
|
|
}
|
|
|
|
if (!empty($result->metadata)) {
|
|
echo "\n📋 Metadata:\n";
|
|
print_r($result->metadata);
|
|
}
|
|
|
|
echo "\n" . ($result->itemsWarmed > 0 ? "✅ SUCCESS" : "❌ FAILURE") . "\n";
|