argument('identifier'); try { // 템플릿 디렉토리 스캔 및 로드 $this->templateManager->loadTemplates(); if ($identifier) { // 특정 템플릿 캐시만 삭제 $this->clearSingleTemplateCache($identifier); } else { // 모든 템플릿 캐시 삭제 $this->clearAllTemplateCache(); } return Command::SUCCESS; } catch (\Exception $e) { $this->error('❌ '.$e->getMessage()); Log::error('템플릿 캐시 삭제 실패', [ 'identifier' => $identifier, 'error' => $e->getMessage(), ]); return Command::FAILURE; } } /** * 특정 템플릿의 캐시 삭제 */ private function clearSingleTemplateCache(string $identifier): void { // 템플릿 존재 확인 $template = $this->templateManager->getTemplate($identifier); if (! $template) { throw new \Exception(__('templates.errors.not_found', ['template' => $identifier])); } $this->info(__('templates.commands.cache_clear.clearing_single', ['template' => $identifier])); $clearedCount = 0; // 1. 레이아웃 캐시 삭제 $templateRecord = Template::where('identifier', $identifier)->first(); if ($templateRecord) { $layouts = TemplateLayout::where('template_id', $templateRecord->id)->get(); foreach ($layouts as $layout) { $this->cache->forget("layout.{$identifier}.{$layout->name}"); $clearedCount++; } } // 2. Routes 캐시 삭제 $this->cache->forget("template.routes.{$identifier}"); $clearedCount++; // 3. 다국어 파일 캐시 삭제 $supportedLocales = config('app.supported_locales', ['ko', 'en']); foreach ($supportedLocales as $locale) { $this->cache->forget("template.language.{$identifier}.{$locale}"); $clearedCount++; } // 4. 활성 템플릿 타입 캐시 삭제 if ($templateRecord) { $this->cache->forget("templates.active.{$templateRecord->type}"); $clearedCount++; } $this->info('✅ '.__('templates.commands.cache_clear.success_single', [ 'template' => $identifier, 'count' => $clearedCount, ])); Log::info(__('templates.commands.cache_clear.success_single', [ 'template' => $identifier, 'count' => $clearedCount, ])); } /** * 모든 템플릿 캐시 삭제 */ private function clearAllTemplateCache(): void { $this->info(__('templates.commands.cache_clear.clearing_all')); $clearedCount = 0; $supportedLocales = config('app.supported_locales', ['ko', 'en']); // 모든 설치된 템플릿의 캐시 삭제 $templates = Template::all(); foreach ($templates as $templateRecord) { // 1. 레이아웃 캐시 삭제 $layouts = TemplateLayout::where('template_id', $templateRecord->id)->get(); foreach ($layouts as $layout) { $this->cache->forget("layout.{$templateRecord->identifier}.{$layout->name}"); $clearedCount++; } // 2. Routes 캐시 삭제 $this->cache->forget("template.routes.{$templateRecord->identifier}"); $clearedCount++; // 3. 다국어 파일 캐시 삭제 foreach ($supportedLocales as $locale) { $this->cache->forget("template.language.{$templateRecord->identifier}.{$locale}"); $clearedCount++; } } // 4. 활성 템플릿 타입 캐시 삭제 $this->cache->forget('templates.active.admin'); $this->cache->forget('templates.active.user'); $clearedCount += 2; // 5. 확장 프론트엔드 병합 번들 파일 전체 삭제 (템플릿 캐시 정리는 페이지 전면 갱신) $clearedCount += $this->bundleService->clearBundles(); $this->info('✅ '.__('templates.commands.cache_clear.success_all', [ 'count' => $clearedCount, ])); Log::info(__('templates.commands.cache_clear.success_all', [ 'count' => $clearedCount, ])); } }