Enable Discovery debug logging for production troubleshooting

- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
2025-08-11 20:13:26 +02:00
parent 59fd3dd3b1
commit 55a330b223
3683 changed files with 2956207 additions and 16948 deletions

View File

@@ -1,63 +1,107 @@
<?php
declare(strict_types=1);
namespace App\Framework\Cache;
use App\Framework\Async\AsyncService;
use App\Framework\Cache\Compression\GzipCompression;
use App\Framework\Cache\Compression\NullCompression;
use App\Framework\Cache\Driver\ApcuCache;
use App\Framework\Cache\Driver\FileCache;
use App\Framework\Cache\Driver\InMemoryCache;
use App\Framework\Cache\Driver\NullCache;
use App\Framework\Cache\Driver\RedisCache;
use App\Framework\Cache\Serializer\JsonSerializer;
use App\Framework\Cache\Serializer\PhpSerializer;
use App\Framework\Cache\Metrics\CacheMetrics;
use App\Framework\Cache\Metrics\CacheMetricsInterface;
use App\Framework\Cache\Metrics\MetricsDecoratedCache;
use App\Framework\DI\Container;
use App\Framework\DI\Initializer;
use App\Framework\Performance\Contracts\PerformanceCollectorInterface;
use App\Framework\Redis\RedisConfig;
use App\Framework\Redis\RedisConnection;
use App\Framework\Serializer\Json\JsonSerializer;
use App\Framework\Serializer\Php\PhpSerializer;
final readonly class CacheInitializer
{
public function __construct(
private PerformanceCollectorInterface $performanceCollector,
private Container $container,
private ?AsyncService $asyncService = null,
#private CacheMetricsInterface $cacheMetrics,
private string $redisHost = 'redis',
private int $redisPort = 6379,
private int $compressionLevel = -1,
private int $minCompressionLength = 1024
) {}
private int $minCompressionLength = 1024,
private bool $enableAsync = true
) {
}
#[Initializer]
public function __invoke(): Cache
{
$this->clear();
#$this->clear();
$serializer = new PhpSerializer();
$serializer = new JsonSerializer();
#$serializer = new JsonSerializer();
$compression = new GzipCompression($this->compressionLevel, $this->minCompressionLength);
// L1 Cache:
if(function_exists('apcu_clear_cache')) {
$apcuCache = new GeneralCache(new APCuCache);
}else {
$apcuCache = new GeneralCache(new InMemoryCache);
// L1 Cache: Fast cache with compression for larger values
if (function_exists('apcu_clear_cache')) {
$apcuCache = new GeneralCache(new APCuCache(), $serializer, $compression);
} else {
$apcuCache = new GeneralCache(new InMemoryCache(), $serializer, $compression);
}
$compressedApcuCache = new CompressionCacheDecorator(
$apcuCache,
$compression,
$serializer
);
// L2 Cache: Persistent cache with compression
try {
$redisConfig = new RedisConfig(
host: $this->redisHost,
port: $this->redisPort,
database: 1 // Use DB 1 for cache
);
$redisConnection = new RedisConnection($redisConfig, 'cache');
$redisCache = new GeneralCache(new RedisCache($redisConnection), $serializer, $compression);
} catch (\Throwable $e) {
// Fallback to file cache if Redis is not available
error_log("Redis not available, falling back to file cache: " . $e->getMessage());
$redisCache = new GeneralCache(new FileCache(), $serializer, $compression);
}
// L2 Cache:
$redisCache = new GeneralCache(new RedisCache(host: $this->redisHost, port: $this->redisPort));
$compressedRedisCache = new CompressionCacheDecorator(
$redisCache,
$compression,
$serializer
);
#$redisCache->clear();
$multiLevelCache = new MultiLevelCache($compressedApcuCache, $compressedRedisCache);
$multiLevelCache = new MultiLevelCache($apcuCache, $redisCache);
#return $multiLevelCache;
return new LoggingCacheDecorator($multiLevelCache);
#return new LoggingCacheDecorator($multiLevelCache);
#return new GeneralCache(new NullCache(), $serializer, $compression);
// Create cache metrics instance directly to avoid DI circular dependency
$cacheMetrics = new CacheMetrics();
// Bind it to container for other services that might need it
if (! $this->container->has(CacheMetricsInterface::class)) {
$this->container->bind(CacheMetricsInterface::class, $cacheMetrics);
}
// Add comprehensive cache metrics with integrated performance tracking
$metricsCache = new MetricsDecoratedCache(
$multiLevelCache,
$cacheMetrics,
'MultiLevel',
$this->performanceCollector,
true // Performance tracking enabled
);
// Wrap with SmartCache for intelligent async processing and pattern support
return new SmartCache(
$metricsCache,
$this->asyncService,
$this->enableAsync
);
#return new GeneralCache(new NullCache());