fix(core): 공개 템플릿 config 캐시 무효화 누락과 확장 캐시 삭제 경로 동종 결함 정비

공개 config.json 의 고정 캐시 키(template.config.{identifier})가 어떤 갱신
경로에서도 forget 되지 않아 template:update/cache-clear/비활성화/삭제 후에도
최대 1시간(TTL) 이전 manifest 로 응답되던 결함(공개 )을 수정한다.

- TemplateManager::clearTemplateCache 공개화 — config/components_manifest(두
 변종)/현재 버전 routes·language 키 능동 forget, updateTemplate cleanup 호출
- forgetLayoutCacheKeys 가 편집기용 .with_source_meta 변종까지 삭제
- ext.cache_version 쓰기를 incrementExtensionCacheVersion 단일 지점으로 통일
- module/plugin:cache-clear 의 유령 키 forget 을 실재 캐시(레이아웃 서빙/해석
 캐시, 상태 키, 미들웨어 인덱스, 버전 bump) 무효화로 교체
- 공개 routes/language/layout API 의 ?v 생략 폴백을 0 → 현재 버전으로 교정
This commit is contained in:
HeuJung committed 2026-08-17 13:22:48 +09:00
1 parent 09a700e4c7
commit e819db9d42
27 files changed
+891 -247

No files matched your search

+58 -22
View File
@@ -1687,13 +1687,9 @@ class TemplateManager implements TemplateManagerInterface
}
if (! in_array($override->name, $registeredLayoutNames)) {
// 캐시 삭제 (레코드 삭제 전에 수행)
$cacheKey = "template.{$templateId}.layout.{$override->name}";
$this->cache()->forget($cacheKey);
$sourceHash = md5($override->source_type?->value.$override->source_identifier);
$cacheKeyWithHash = "template.{$templateId}.layout.{$override->name}.{$sourceHash}";
$this->cache()->forget($cacheKeyWithHash);
// 캐시 삭제 (레코드 삭제 전에 수행) — 키 조립은 트레이트 단일 지점에 위임
// (.with_source_meta 변종 포함, 수작업 키 목록의 규약 드리프트 방지)
$this->forgetLayoutCacheKeys($override, $templateName);
$override->forceDelete();
$deletedCount++;
@@ -1740,14 +1736,10 @@ class TemplateManager implements TemplateManagerInterface
}
foreach ($overrideLayouts as $layout) {
// 기본 캐시 키 패턴으로 삭제
$cacheKey = "template.{$templateId}.layout.{$layout->name}";
$this->cache()->forget($cacheKey);
// sourceHash를 포함한 캐시 키도 삭제 (LayoutService의 캐시 키 패턴)
$sourceHash = md5($layout->source_type?->value.$layout->source_identifier);
$cacheKeyWithHash = "template.{$templateId}.layout.{$layout->name}.{$sourceHash}";
$this->cache()->forget($cacheKeyWithHash);
// 키 조립은 트레이트 단일 지점에 위임 (.with_source_meta 변종 포함).
// 이 경로는 identifier 를 보유하지 않으므로 '' 전달 — 버전 포함 공개
// 서빙 키는 종전과 동일하게 버전 bump 로 무효화된다.
$this->forgetLayoutCacheKeys($layout, '');
}
Log::info(__('templates.info.override_layouts_cache_invalidated'), [
@@ -1794,41 +1786,79 @@ class TemplateManager implements TemplateManagerInterface
/**
* 템플릿 관련 모든 캐시를 삭제합니다.
*
* 템플릿 라이프사이클(update/deactivate/uninstall/cache-clear)이 공유하는
* 무효화 단일 지점이다. 버전 접미사 없는 고정 키(`template.config.{identifier}`,
* `template.{id|identifier}.components_manifest`)는 캐시 버전 bump 로 무효화되지
* 않으므로 여기서 능동 forget 한다 — 누락 시 공개 config.json 이 TTL(1시간) 동안
* 이전 manifest 로 응답된다 (#588, 공개 #119).
*
* template:cache-clear 커맨드가 호출할 수 있도록 public 이다.
*
* @param string $templateIdentifier 템플릿 식별자
* @return int 능동 삭제를 시도한 캐시 키 수
*/
protected function clearTemplateCache(string $templateIdentifier): void
public function clearTemplateCache(string $templateIdentifier): int
{
$clearedCount = 0;
// identifier 만으로 가능한 고정 키 forget — uninstall 등 DB 레코드가 이미
// 없는 상황에서도 반드시 수행되어야 하므로 레코드 조회보다 먼저 둔다.
$this->cache()->forget("template.config.{$templateIdentifier}");
$clearedCount++;
// components_manifest identifier 변종 (ComponentExists 는 int|string 수용)
$this->cache()->forget("template.{$templateIdentifier}.components_manifest");
$clearedCount++;
// 활성 템플릿 + 레이아웃 무변경 업데이트 경로는 캐시 버전 bump 가 없어
// 현재 버전 routes/language 키가 stale 로 남는다 — warmTemplateCache() 와
// 대칭으로 현재 버전 키를 능동 삭제한다 (이전 버전 키는 TTL 자연 만료).
$cacheVersion = self::getExtensionCacheVersion();
$this->cache()->forget("template.routes.{$templateIdentifier}.v{$cacheVersion}");
$clearedCount++;
foreach (config('app.supported_locales', ['ko', 'en']) as $locale) {
$this->cache()->forget("template.language.{$templateIdentifier}.{$locale}.v{$cacheVersion}");
$clearedCount++;
}
// DB 기반 조회 — 파일 시스템 상태와 무관하게 캐시 삭제 보장
// (파일 교체 중이거나 reloadTemplate() 전에도 캐시를 확실히 삭제)
$templateRecord = $this->templateRepository->findByIdentifier($templateIdentifier);
if (! $templateRecord) {
return;
return $clearedCount;
}
// 레이아웃 캐시 삭제 (버전 없는 내부 캐시)
$this->clearLayoutCaches($templateIdentifier);
// components_manifest 숫자 id 변종 (StoreLayoutRequest 가 integer 검증 — 실운영 키)
$this->cache()->forget("template.{$templateRecord->id}.components_manifest");
$clearedCount++;
// Routes/다국어 캐시는 버전 포함 키이므로 incrementExtensionCacheVersion() + TTL로 무효화됨
// 레이아웃 캐시 삭제 (버전 없는 내부 캐시)
$clearedCount += $this->clearLayoutCaches($templateIdentifier);
Log::info(__('templates.info.cache_cleared'), [
'template' => $templateIdentifier,
]);
return $clearedCount;
}
/**
* 템플릿의 모든 레이아웃 캐시를 삭제합니다.
*
* @param string $templateIdentifier 템플릿 식별자
* @return int 캐시를 무효화한 레이아웃 수
*/
protected function clearLayoutCaches(string $templateIdentifier): void
protected function clearLayoutCaches(string $templateIdentifier): int
{
// 템플릿의 모든 레이아웃 조회
$template = $this->templateRepository->findByIdentifier($templateIdentifier);
if (! $template) {
return;
return 0;
}
$this->invalidateTemplateLayoutCache($template->id, $templateIdentifier);
return $this->layoutRepository->getByTemplateId($template->id)->count();
}
/**
@@ -3110,6 +3140,12 @@ class TemplateManager implements TemplateManagerInterface
$onProgress?->__invoke('cleanup', '정리 중...');
ExtensionBackupHelper::deleteBackup($backupPath);
// 고정 키(config/components_manifest) + 현재 버전 routes/language 키 능동 삭제.
// 비활성 업데이트·레이아웃 무변경 업데이트 경로는 버전 bump 가 없어 이 호출이
// 없으면 공개 config.json 이 TTL 동안 이전 manifest 로 응답된다 (#588, 공개 #119).
// 활성 경로의 refreshTemplateLayouts() 경유 중복 삭제는 forget 멱등이라 무해.
$this->clearTemplateCache($identifier);
$this->clearAllTemplateLanguageCaches();
$this->clearAllTemplateRoutesCaches();
// refreshTemplateLayouts() 내부에서 변경 시 incrementExtensionCacheVersion() 호출됨
@@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Log;
* 버전 없는 내부 캐시 키를 능동 삭제합니다:
* 1. template.{templateId}.layout.{layoutName} - LayoutService에서 사용
* 2. template.{templateId}.layout.{layoutName}.{sourceHash} - 모듈/플러그인 레이아웃
* 3. 위 두 형태의 `.with_source_meta` 접미사 변종 - 편집기용 병합 응답 캐시
*
* 버전 포함 캐시 (layout.{identifier}.{name}.v{version})는
* incrementExtensionCacheVersion() + TTL로 무효화됩니다.
@@ -98,20 +99,26 @@ trait InvalidatesLayoutCache
$cache = $this->resolveLayoutCache();
// 1. LayoutService 내부 캐시 (버전 없음 → 능동 삭제)
$cache->forget("template.{$layout->template_id}.layout.{$layout->name}");
// 편집기용 병합 응답은 `.with_source_meta` 접미사 키로 별도 캐싱되므로
// (LayoutService::getMergedLayoutCacheKey) 두 변종을 함께 지운다 —
// 접미사 키를 남기면 activate/deactivate/uninstall/refresh 후에도
// 편집기가 stale 병합 캐시를 받는다 (#588).
$cache->forget($this->buildLayoutCacheKey($layout->template_id, $layout->name));
$cache->forget($this->buildLayoutCacheKey($layout->template_id, $layout->name, withSourceMeta: true));
// 2. 소스 해시 포함 키 (버전 없음 → 능동 삭제)
// 2. 소스 해시 포함 키 (버전 없음 → 능동 삭제) — 접미사는 소스 해시 뒤
if ($layout->source_type && $layout->source_identifier) {
$sourceHash = md5($layout->source_type->value.$layout->source_identifier);
$cache->forget("template.{$layout->template_id}.layout.{$layout->name}.{$sourceHash}");
$sourceType = $layout->source_type->value;
$cache->forget($this->buildLayoutCacheKey($layout->template_id, $layout->name, $sourceType, $layout->source_identifier));
$cache->forget($this->buildLayoutCacheKey($layout->template_id, $layout->name, $sourceType, $layout->source_identifier, true));
}
// 3. PublicLayoutController 캐시 (버전 포함) — 일반 응답 + 편집기(`.meta`) 응답 두 키 모두.
// PublicLayoutController::serve() 가 `with_source_meta=1`(레이아웃 편집기) 응답을 `.meta`
// 접미사 별도 키로 캐싱하므로, 그 키를 함께 삭제하지 않으면 템플릿/레이아웃 상태 변화
// (refresh-layout / activate / deactivate / uninstall 등) 후에도 편집기가 stale 캐시를
// 받는다. 레이아웃
// 저장 경로(LayoutService::clearPublicServingCache)는 이미 두 키를 지우므로 정합을 맞춘다.
// 받는다. 레이아웃 저장 경로(LayoutService::clearPublicServingCache)는 이미 두 키를
// 지우므로 정합을 맞춘다.
if ($templateIdentifier) {
$cacheVersion = (int) $cache->get('ext.cache_version', 0);
$cache->forget("layout.{$templateIdentifier}.{$layout->name}.v{$cacheVersion}");
@@ -137,26 +144,32 @@ trait InvalidatesLayoutCache
/**
* 레이아웃 캐시 키를 생성합니다.
*
* `$withSourceMeta` 가 true 면 `.with_source_meta` 접미사를 붙인다 — 편집기용
* 병합 응답 키(LayoutService::getMergedLayoutCacheKey 와 동형, 접미사는 소스 해시 뒤).
*
* @param int $templateId 템플릿 ID
* @param string $layoutName 레이아웃 이름
* @param string|null $sourceType 소스 타입 (선택)
* @param string|null $sourceIdentifier 소스 식별자 (선택)
* @param bool $withSourceMeta 편집기용 병합 응답 키 여부 (선택)
* @return string 캐시 키
*/
protected function buildLayoutCacheKey(
int $templateId,
string $layoutName,
?string $sourceType = null,
?string $sourceIdentifier = null
?string $sourceIdentifier = null,
bool $withSourceMeta = false
): string {
$baseKey = "template.{$templateId}.layout.{$layoutName}";
$metaSuffix = $withSourceMeta ? '.with_source_meta' : '';
if ($sourceType && $sourceIdentifier) {
$sourceHash = md5($sourceType.$sourceIdentifier);
return "{$baseKey}.{$sourceHash}";
return "{$baseKey}.{$sourceHash}{$metaSuffix}";
}
return $baseKey;
return "{$baseKey}{$metaSuffix}";
}
}