cachePath)) { mkdir($this->cachePath, 0755, true); } /* // Initialisiere Smart Cache System if ($this->useSmartCache && $cache) { #$analyzer = new TemplateAnalyzer(); #$fragmentCache = new FragmentCacheManager($cache); $this->smartCache = new QuickSmartCacheReplacement( cache: $cache, #analyzer : $analyzer, #fragmentCache: $fragmentCache, loader: $this->loader, processor: $this->processor ); } else { $this->smartCache = null; }*/ // Neues Cache-System initialisieren if ($this->cacheEnabled && $cache) { $analyzer = new SmartTemplateAnalyzer($this->loader); $fragmentCache = new TaggedFragmentCache($cache); $this->cacheManager = new CacheManager( cache: $cache, analyzer: $analyzer, fragmentCache: $fragmentCache ); } else { $this->cacheManager = null; } } public function render(RenderContext $context): string { // Verwende neuen CacheManager wenn verfügbar if ($this->cacheManager) { $templateContext = new TemplateContext( template: $context->template, data: $context->data, controllerClass: $context->controllerClass, metadata: $context->metaData ? ['meta' => $context->metaData] : [] ); return $this->cacheManager->render($templateContext, function () use ($context) { return $this->renderDirect($context); }); } // Fallback ohne Cache /*return $this->legacyCacheEnabled ? $this->renderWithLegacyCache($context) : $this->renderDirect($context);*/ } /*private function renderWithLegacyCache(RenderContext $context): string { $cacheKey = 'view_' . md5($context->template . '_' . ($context->controllerClass ?? '')); $cacheFile = $this->cachePath . "/{$cacheKey}.cache.html"; // Optimized cache check - avoid expensive filemtime calls if (file_exists($cacheFile)) { $content = $this->storage->get($cacheFile); return $this->processor->render($context, $content); } // Cache miss - render and cache $content = $this->renderDirect($context); $this->storage->put($cacheFile, $content); return $content; }*/ private function renderDirect(RenderContext $context): string { // Optimized single-pass rendering return $this->performanceService->measure( 'template_render', function () use ($context) { // Load template content $content = $this->loader->load($context->template, $context->controllerClass, $context); // Direct processing without intermediate DOM parsing return $this->processor->render($context, $content); }, PerformanceCategory::VIEW, ['template' => $context->template] ); } public function invalidateCache(?string $template = null): int { return $this->cacheManager?->invalidateTemplate($template) ?? 0; } public function getCacheStats(): array { if (! $this->cacheManager) { return ['cache_enabled' => false]; } return [ 'cache_enabled' => true, 'cache_manager' => $this->cacheManager->getStats(), // Diese Methode müsstest du noch implementieren ]; } public function renderPartial(RenderContext $context): string { return $this->renderDirect($context); } }