clear(); $serializer = new PhpSerializer(); #$serializer = new JsonSerializer(); $compression = new GzipCompression($this->compressionLevel, $this->minCompressionLength); // 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); } // L2 Cache: Persistent cache with compression try { // Check if Redis extension is available if (! extension_loaded('redis')) { throw new \RuntimeException('Redis extension is not loaded. Please install php-redis extension or use alternative cache drivers.'); } $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); } #$redisCache->clear(); $multiLevelCache = new MultiLevelCache($apcuCache, $redisCache); #return $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()); } private function clear(): void { apcu_clear_cache(); } }