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:
1 parent
09a700e4c7
commit
e819db9d42
27 files changed
+891
-247
No files matched your search
@@ -2,15 +2,22 @@
|
||||
|
||||
namespace App\Console\Commands\Module;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Contracts\Repositories\LayoutRepositoryInterface;
|
||||
use App\Enums\LayoutSourceType;
|
||||
use App\Extension\ExtensionMiddlewareRegistry;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Extension\Traits\InvalidatesLayoutCache;
|
||||
use App\Services\ExtensionBundleService;
|
||||
use App\Services\LayoutResolverService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ClearModuleCacheCommand extends Command
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
use InvalidatesLayoutCache;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
@@ -27,15 +34,19 @@ class ClearModuleCacheCommand extends Command
|
||||
*/
|
||||
public function __construct(
|
||||
private ModuleManager $moduleManager,
|
||||
private ModuleRepositoryInterface $moduleRepository,
|
||||
private CacheInterface $cache,
|
||||
private ExtensionBundleService $bundleService
|
||||
protected LayoutRepositoryInterface $layoutRepository,
|
||||
private ExtensionBundleService $bundleService,
|
||||
private LayoutResolverService $layoutResolver
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* 실재하는 서버 캐시(모듈 레이아웃 서빙/해석 캐시 + 상태 키 + 미들웨어 인덱스
|
||||
* + 버전 포함 키)를 무효화한다.
|
||||
* 종전 forget 대상(module.config.{id} 등)은 writer 가 없는 유령 키였다 (#588).
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -61,6 +72,11 @@ class ClearModuleCacheCommand extends Command
|
||||
|
||||
$clearedCount = $this->clearModuleCache($identifier);
|
||||
|
||||
// 상태 키(ext.modules.*) + 미들웨어 인덱스 + 버전 포함 키 무효화 (버전 bump)
|
||||
ModuleManager::invalidateModuleStatusCache();
|
||||
ExtensionMiddlewareRegistry::flush();
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
$this->info('✅ '.__('modules.commands.cache_clear.success_single', [
|
||||
'module' => $identifier,
|
||||
'count' => $clearedCount,
|
||||
@@ -69,25 +85,16 @@ class ClearModuleCacheCommand extends Command
|
||||
// 모든 모듈 캐시 삭제
|
||||
$this->info(__('modules.commands.cache_clear.clearing_all'));
|
||||
|
||||
// 전체 모듈 캐시 키 삭제
|
||||
$cacheKeys = [
|
||||
'modules.all',
|
||||
'modules.active',
|
||||
'modules.installed',
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 각 모듈별 캐시 삭제
|
||||
$allModules = $this->moduleManager->getAllModules();
|
||||
foreach ($allModules as $moduleName => $module) {
|
||||
foreach ($this->moduleManager->getAllModules() as $module) {
|
||||
$clearedCount += $this->clearModuleCache($module->getIdentifier());
|
||||
}
|
||||
|
||||
// 상태 키 + 미들웨어 인덱스 + 버전 포함 키 무효화는 전체에서 1회면 충분
|
||||
ModuleManager::invalidateModuleStatusCache();
|
||||
ExtensionMiddlewareRegistry::flush();
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
// 모듈 프론트엔드 병합 번들 파일 삭제 (캐시 키 forget 만으로는 미삭제)
|
||||
$clearedCount += $this->bundleService->clearBundles('module');
|
||||
|
||||
@@ -113,26 +120,23 @@ class ClearModuleCacheCommand extends Command
|
||||
|
||||
/**
|
||||
* 특정 모듈의 캐시를 삭제합니다.
|
||||
*
|
||||
* 모듈이 소유한 실재 서버 캐시는 레이아웃 캐시(서빙/병합 + 해석)다 — 각각
|
||||
* 트레이트(InvalidatesLayoutCache)와 LayoutResolverService 단일 지점으로
|
||||
* 위임해 키 규약 드리프트를 방지한다. 해석 캐시(layout_resolver.*)는 버전
|
||||
* 접미사 없는 고정 키에 레이아웃 row ID 를 저장하므로 능동 삭제하지 않으면
|
||||
* TTL 동안 이전 해석 결과가 유지된다 (#588 동종 보강).
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
* @return int 캐시를 무효화한 레이아웃 수
|
||||
*/
|
||||
private function clearModuleCache(string $identifier): int
|
||||
{
|
||||
$clearedCount = 0;
|
||||
$this->invalidateExtensionLayoutCache($identifier, 'module');
|
||||
$this->layoutResolver->clearResolutionCacheByModule($identifier);
|
||||
|
||||
// 모듈별 캐시 키
|
||||
$cacheKeys = [
|
||||
"module.config.{$identifier}",
|
||||
"module.info.{$identifier}",
|
||||
"module.routes.{$identifier}",
|
||||
"module.permissions.{$identifier}",
|
||||
"module.menus.{$identifier}",
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return $clearedCount;
|
||||
return $this->layoutRepository
|
||||
->getBySourceIdentifier($identifier, LayoutSourceType::Module)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,21 @@
|
||||
|
||||
namespace App\Console\Commands\Plugin;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Repositories\PluginRepositoryInterface;
|
||||
use App\Contracts\Repositories\LayoutRepositoryInterface;
|
||||
use App\Enums\LayoutSourceType;
|
||||
use App\Extension\ExtensionMiddlewareRegistry;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Extension\Traits\InvalidatesLayoutCache;
|
||||
use App\Services\ExtensionBundleService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ClearPluginCacheCommand extends Command
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
use InvalidatesLayoutCache;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
@@ -27,8 +33,7 @@ class ClearPluginCacheCommand extends Command
|
||||
*/
|
||||
public function __construct(
|
||||
private PluginManager $pluginManager,
|
||||
private PluginRepositoryInterface $pluginRepository,
|
||||
private CacheInterface $cache,
|
||||
protected LayoutRepositoryInterface $layoutRepository,
|
||||
private ExtensionBundleService $bundleService
|
||||
) {
|
||||
parent::__construct();
|
||||
@@ -36,6 +41,12 @@ class ClearPluginCacheCommand extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* 실재하는 서버 캐시(플러그인 레이아웃 캐시 + 상태 키 + 미들웨어 인덱스
|
||||
* + 버전 포함 키)를 무효화한다.
|
||||
* 종전 forget 대상(plugin.config.{id} 등)은 writer 가 없는 유령 키였다 (#588).
|
||||
* 해석 캐시(layout_resolver.*)는 모듈 레이아웃 전용이라 플러그인은 비대상
|
||||
* (LayoutResolverService::resolve 의 fromModules 스코프는 plugin row 를 반환하지 않음).
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -61,6 +72,11 @@ class ClearPluginCacheCommand extends Command
|
||||
|
||||
$clearedCount = $this->clearPluginCache($identifier);
|
||||
|
||||
// 상태 키(ext.plugins.*) + 미들웨어 인덱스 + 버전 포함 키 무효화 (버전 bump)
|
||||
PluginManager::invalidatePluginStatusCache();
|
||||
ExtensionMiddlewareRegistry::flush();
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
$this->info('✅ '.__('plugins.commands.cache_clear.success_single', [
|
||||
'plugin' => $identifier,
|
||||
'count' => $clearedCount,
|
||||
@@ -69,25 +85,16 @@ class ClearPluginCacheCommand extends Command
|
||||
// 모든 플러그인 캐시 삭제
|
||||
$this->info(__('plugins.commands.cache_clear.clearing_all'));
|
||||
|
||||
// 전체 플러그인 캐시 키 삭제
|
||||
$cacheKeys = [
|
||||
'plugins.all',
|
||||
'plugins.active',
|
||||
'plugins.installed',
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 각 플러그인별 캐시 삭제
|
||||
$allPlugins = $this->pluginManager->getAllPlugins();
|
||||
foreach ($allPlugins as $pluginName => $plugin) {
|
||||
foreach ($this->pluginManager->getAllPlugins() as $plugin) {
|
||||
$clearedCount += $this->clearPluginCache($plugin->getIdentifier());
|
||||
}
|
||||
|
||||
// 상태 키 + 미들웨어 인덱스 + 버전 포함 키 무효화는 전체에서 1회면 충분
|
||||
PluginManager::invalidatePluginStatusCache();
|
||||
ExtensionMiddlewareRegistry::flush();
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
// 플러그인 프론트엔드 병합 번들 파일 삭제 (캐시 키 forget 만으로는 미삭제)
|
||||
$clearedCount += $this->bundleService->clearBundles('plugin');
|
||||
|
||||
@@ -113,25 +120,18 @@ class ClearPluginCacheCommand extends Command
|
||||
|
||||
/**
|
||||
* 특정 플러그인의 캐시를 삭제합니다.
|
||||
*
|
||||
* 플러그인이 소유한 실재 서버 캐시는 레이아웃 캐시뿐이다 — 트레이트 단일 지점
|
||||
* (InvalidatesLayoutCache)으로 위임해 키 규약 드리프트를 방지한다.
|
||||
*
|
||||
* @return int 캐시를 무효화한 레이아웃 수
|
||||
*/
|
||||
private function clearPluginCache(string $identifier): int
|
||||
{
|
||||
$clearedCount = 0;
|
||||
$this->invalidateExtensionLayoutCache($identifier, 'plugin');
|
||||
|
||||
// 플러그인별 캐시 키 (메뉴 캐시 없음)
|
||||
$cacheKeys = [
|
||||
"plugin.config.{$identifier}",
|
||||
"plugin.info.{$identifier}",
|
||||
"plugin.routes.{$identifier}",
|
||||
"plugin.permissions.{$identifier}",
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
if ($this->cache->forget($key)) {
|
||||
$clearedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return $clearedCount;
|
||||
return $this->layoutRepository
|
||||
->getBySourceIdentifier($identifier, LayoutSourceType::Plugin)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,17 @@
|
||||
|
||||
namespace App\Console\Commands\Template;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Extension\TemplateManager;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Models\Template;
|
||||
use App\Models\TemplateLayout;
|
||||
use App\Services\ExtensionBundleService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ClearTemplateCacheCommand extends Command
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
@@ -28,7 +29,6 @@ class ClearTemplateCacheCommand extends Command
|
||||
*/
|
||||
public function __construct(
|
||||
private TemplateManager $templateManager,
|
||||
private CacheInterface $cache,
|
||||
private ExtensionBundleService $bundleService
|
||||
) {
|
||||
parent::__construct();
|
||||
@@ -67,6 +67,10 @@ class ClearTemplateCacheCommand extends Command
|
||||
|
||||
/**
|
||||
* 특정 템플릿의 캐시 삭제
|
||||
*
|
||||
* 라이프사이클(update/deactivate/uninstall)과 동일한 무효화 단일 지점
|
||||
* (`TemplateManager::clearTemplateCache()`)을 경유한다 — 커맨드가 키 목록을
|
||||
* 별도로 유지하면 키 규약 변경 시 유령 forget 으로 사문화된다 (#588, 공개 #119).
|
||||
*/
|
||||
private function clearSingleTemplateCache(string $identifier): void
|
||||
{
|
||||
@@ -78,34 +82,12 @@ class ClearTemplateCacheCommand extends Command
|
||||
|
||||
$this->info(__('templates.commands.cache_clear.clearing_single', ['template' => $identifier]));
|
||||
|
||||
$clearedCount = 0;
|
||||
// 고정 키(config/components_manifest) + 현재 버전 routes/language + 레이아웃 캐시
|
||||
$clearedCount = $this->templateManager->clearTemplateCache($identifier);
|
||||
|
||||
// 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++;
|
||||
}
|
||||
// 상태 키(ext.templates.*) + 버전 포함 키 무효화 (버전 bump)
|
||||
TemplateManager::invalidateTemplateStatusCache();
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
$this->info('✅ '.__('templates.commands.cache_clear.success_single', [
|
||||
'template' => $identifier,
|
||||
@@ -126,36 +108,17 @@ class ClearTemplateCacheCommand extends Command
|
||||
$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++;
|
||||
}
|
||||
// 모든 설치된 템플릿의 캐시 삭제 (설치 레코드 기준 — 라이프사이클과 동일 지점)
|
||||
foreach (Template::all() as $templateRecord) {
|
||||
$clearedCount += $this->templateManager->clearTemplateCache($templateRecord->identifier);
|
||||
}
|
||||
|
||||
// 4. 활성 템플릿 타입 캐시 삭제
|
||||
$this->cache->forget('templates.active.admin');
|
||||
$this->cache->forget('templates.active.user');
|
||||
$clearedCount += 2;
|
||||
// 상태 키 + 버전 포함 키 무효화는 전체에서 1회면 충분
|
||||
TemplateManager::invalidateTemplateStatusCache();
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
// 5. 확장 프론트엔드 병합 번들 파일 전체 삭제 (템플릿 캐시 정리는 페이지 전면 갱신)
|
||||
// 확장 프론트엔드 병합 번들 파일 전체 삭제 (템플릿 캐시 정리는 페이지 전면 갱신)
|
||||
$clearedCount += $this->bundleService->clearBundles();
|
||||
|
||||
$this->info('✅ '.__('templates.commands.cache_clear.success_all', [
|
||||
|
||||
@@ -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}";
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@
|
||||
namespace App\Http\Controllers\Api\Public;
|
||||
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Helpers\PermissionHelper;
|
||||
use App\Http\Controllers\Api\Base\PublicBaseController;
|
||||
use App\Services\LayoutService;
|
||||
use App\Services\TemplateService;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
@@ -17,6 +19,8 @@ use Illuminate\Http\Response;
|
||||
*/
|
||||
class PublicLayoutController extends PublicBaseController
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
|
||||
/**
|
||||
* 레이아웃 캐시 TTL (초)
|
||||
*/
|
||||
@@ -69,7 +73,10 @@ class PublicLayoutController extends PublicBaseController
|
||||
// 키만 forget 하므로 키 형식이 어긋나 무효화가 빗나간다(저장/복원 후 편집기 캔버스만
|
||||
// stale). nonce 는 브라우저 HTTP 캐시 우회용(URL·ETag 차이로 이미 달성)이고, 서버 캐시 키
|
||||
// 정합은 정수 버전이 SSoT 다. `(int)` 캐스팅은 PHP 가 소수점에서 절단해 정수부만 남긴다.
|
||||
$cacheVersion = (int) request()->query('v', 0);
|
||||
// `?v` 생략 시 현재 버전으로 폴백 — 리터럴 0 폴백은 워밍/무효화 어느 경로에도
|
||||
// 걸리지 않는 `.v0` 영구 사각 키를 만든다 (#588).
|
||||
$rawVersion = request()->query('v');
|
||||
$cacheVersion = $rawVersion !== null ? (int) $rawVersion : self::getExtensionCacheVersion();
|
||||
|
||||
// 편집기 출처 메타 옵션
|
||||
// - 옵션이 truthy 면 각 노드에 `__source` 메타를 부여한 응답을 반환
|
||||
@@ -119,7 +126,7 @@ class PublicLayoutController extends PublicBaseController
|
||||
$mergedLayout,
|
||||
self::CACHE_TTL
|
||||
);
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
} catch (ModelNotFoundException $e) {
|
||||
// 레이아웃 또는 부모 레이아웃을 찾을 수 없음 - 예외 메시지 전달
|
||||
return $this->notFound($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
*/
|
||||
class PublicTemplateController extends PublicBaseController
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
|
||||
public function __construct(
|
||||
private TemplateService $templateService,
|
||||
private TemplateLayoutAttachmentService $layoutAttachmentService,
|
||||
@@ -40,8 +42,11 @@ class PublicTemplateController extends PublicBaseController
|
||||
// API 사용량 기록
|
||||
$this->logApiUsage('templates.routes', ['identifier' => $identifier]);
|
||||
|
||||
// 캐시 버전을 키에 포함하여 모듈/플러그인 변경 시 캐시 무효화
|
||||
$cacheVersion = request()->query('v', 0);
|
||||
// 캐시 버전을 키에 포함하여 모듈/플러그인 변경 시 캐시 무효화.
|
||||
// `?v` 생략 시 현재 버전으로 폴백 — 리터럴 0 폴백은 워밍/무효화 어느 경로에도
|
||||
// 걸리지 않는 `.v0` 영구 사각 키를 만든다 (#588). `(int)` 캐스트로 키 위생 겸용.
|
||||
$rawVersion = request()->query('v');
|
||||
$cacheVersion = $rawVersion !== null ? (int) $rawVersion : self::getExtensionCacheVersion();
|
||||
|
||||
// 확장 업데이트 중에는 활성 디렉토리가 잠시 비어 그 모듈의 라우트가 통째로 빠진다.
|
||||
// 그 순간의 응답을 버전 키에 캐시하면 업데이트가 끝난 뒤에도 캐시가 만료될 때까지
|
||||
@@ -226,7 +231,7 @@ class PublicTemplateController extends PublicBaseController
|
||||
|
||||
// 캐시 버전을 응답에 포함하여 프론트엔드가 API 호출 시 사용하도록 함
|
||||
$responseData = $configData['data'];
|
||||
$responseData['cache_version'] = ClearsTemplateCaches::getExtensionCacheVersion();
|
||||
$responseData['cache_version'] = self::getExtensionCacheVersion();
|
||||
|
||||
return $this->success(
|
||||
__('templates.messages.config_retrieved'),
|
||||
@@ -249,8 +254,10 @@ class PublicTemplateController extends PublicBaseController
|
||||
'locale' => $locale,
|
||||
]);
|
||||
|
||||
// 캐시 버전을 키에 포함하여 모듈/플러그인 변경 시 캐시 무효화
|
||||
$cacheVersion = request()->query('v', 0);
|
||||
// 캐시 버전을 키에 포함하여 모듈/플러그인 변경 시 캐시 무효화.
|
||||
// `?v` 생략 시 현재 버전으로 폴백 (getRoutes 와 동일 — `.v0` 사각 키 방지)
|
||||
$rawVersion = request()->query('v');
|
||||
$cacheVersion = $rawVersion !== null ? (int) $rawVersion : self::getExtensionCacheVersion();
|
||||
|
||||
// 캐싱된 응답 반환 (1시간 유효)
|
||||
$languageData = $this->cached(
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Listeners\LayoutEditor;
|
||||
|
||||
use App\Contracts\Extension\HookListenerInterface;
|
||||
use App\Contracts\Repositories\TemplateCustomTranslationRepositoryInterface;
|
||||
use App\Extension\Cache\CoreCacheDriver;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Services\LanguagePack\CustomTranslationUsageScanner;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -30,6 +30,8 @@ use Throwable;
|
||||
*/
|
||||
class MarkOrphanedCustomTranslations implements HookListenerInterface
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
|
||||
/**
|
||||
* @param TemplateCustomTranslationRepositoryInterface $repository 커스텀 키 리포지토리
|
||||
* @param CustomTranslationUsageScanner $scanner 키 사용 스캐너 (순수)
|
||||
@@ -124,12 +126,11 @@ class MarkOrphanedCustomTranslations implements HookListenerInterface
|
||||
/**
|
||||
* 다국어 캐시 버전을 무효화합니다.
|
||||
*
|
||||
* `ext.cache_version` 은 코어 소유 키이므로 컨테이너 바인딩에 의존하지 않고
|
||||
* 항상 CoreCacheDriver(`g7:core:` 네임스페이스)를 직접 생성합니다
|
||||
* (ClearsTemplateCaches 트레이트와 동일 SSoT).
|
||||
* `ext.cache_version` 쓰기는 ClearsTemplateCaches 트레이트 단일 지점 경유 —
|
||||
* 트레이트가 고정 CoreCacheDriver + 메모이즈 스토어로 write/read 일관성을 보장한다.
|
||||
*/
|
||||
private function invalidateLanguageCache(): void
|
||||
{
|
||||
(new CoreCacheDriver(config('cache.default', 'array')))->put('ext.cache_version', time());
|
||||
$this->incrementExtensionCacheVersion();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Repositories\LayoutExtensionRepositoryInterface;
|
||||
use App\Contracts\Repositories\LayoutExtensionVersionRepositoryInterface;
|
||||
use App\Contracts\Repositories\LayoutRepositoryInterface;
|
||||
@@ -15,6 +14,7 @@ use App\Extension\HookManager;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\TemplateManager;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Extension\Traits\ComputesLayoutContentHash;
|
||||
use App\Models\LayoutExtension;
|
||||
use App\Models\TemplateLayoutExtensionVersion;
|
||||
@@ -32,6 +32,7 @@ use Illuminate\Support\Facades\Log;
|
||||
*/
|
||||
class LayoutExtensionService
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
use ComputesLayoutContentHash;
|
||||
|
||||
/**
|
||||
@@ -123,7 +124,6 @@ class LayoutExtensionService
|
||||
private LayoutExtensionRepositoryInterface $repository,
|
||||
private LayoutExtensionVersionRepositoryInterface $versionRepository,
|
||||
private LayoutRepositoryInterface $layoutRepository,
|
||||
private CacheInterface $cache,
|
||||
private PluginRepositoryInterface $pluginRepository,
|
||||
private ModuleRepositoryInterface $moduleRepository,
|
||||
) {}
|
||||
@@ -1830,8 +1830,10 @@ class LayoutExtensionService
|
||||
}
|
||||
|
||||
// extension_point 는 여러 레이아웃에서 사용될 수 있으므로 전역 캐시 버전 갱신
|
||||
// overlay 도 프론트엔드 브라우저 캐시 무효화를 위해 동일하게 갱신
|
||||
$this->cache->put('ext.cache_version', time());
|
||||
// overlay 도 프론트엔드 브라우저 캐시 무효화를 위해 동일하게 갱신.
|
||||
// 쓰기는 트레이트 단일 지점(고정 CoreCacheDriver + 메모이즈 스토어) 경유 —
|
||||
// 주입 CacheInterface 직접 put 은 재바인딩/스토어 상이 시 read 와 어긋난다.
|
||||
$this->incrementExtensionCacheVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Exceptions\CircularReferenceException;
|
||||
use App\Exceptions\ConcurrentModificationException;
|
||||
use App\Exceptions\LayoutIncludeException;
|
||||
use App\Extension\HookManager;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Helpers\PermissionHelper;
|
||||
use App\Models\TemplateLayout;
|
||||
use App\Models\User;
|
||||
@@ -21,6 +22,8 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LayoutService
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
|
||||
/**
|
||||
* LayoutRepository, LayoutVersionRepository, TemplateRepository, LayoutResolverService 및 LayoutExtensionService 주입
|
||||
*/
|
||||
@@ -1470,7 +1473,9 @@ class LayoutService
|
||||
// 프론트엔드 브라우저 캐시 무효화를 위해 ext.cache_version 증가
|
||||
// PublicLayoutController가 ?v={version} 기반 HTTP 캐시를 사용하므로
|
||||
// 버전 변경 시 브라우저가 새 URL로 인식하여 캐시를 우회합니다.
|
||||
$this->cache->put('ext.cache_version', time());
|
||||
// 쓰기는 트레이트 단일 지점(고정 CoreCacheDriver + 메모이즈 스토어) 경유 —
|
||||
// 주입 CacheInterface 직접 put 은 재바인딩/스토어 상이 시 read 와 어긋난다.
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
// After 훅 - 레이아웃 업데이트 후
|
||||
HookManager::doAction('core.layout.after_update', $layout, $templateId, $name, $data);
|
||||
@@ -1579,8 +1584,8 @@ class LayoutService
|
||||
// 캐시 무효화
|
||||
$this->clearDependentLayoutsCache($templateId, $name);
|
||||
|
||||
// 프론트엔드 브라우저 캐시 무효화
|
||||
$this->cache->put('ext.cache_version', time());
|
||||
// 프론트엔드 브라우저 캐시 무효화 (트레이트 단일 지점 경유)
|
||||
$this->incrementExtensionCacheVersion();
|
||||
|
||||
// After 훅 - 버전 복원 후
|
||||
HookManager::doAction('core.layout.after_version_restore', $newVersion, $templateId, $name, $versionId);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Contracts\Extension\CacheInterface;
|
||||
use App\Contracts\Repositories\TemplateCustomTranslationRepositoryInterface;
|
||||
use App\Exceptions\ConcurrentModificationException;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Models\TemplateCustomTranslation;
|
||||
use App\Services\LanguagePack\CustomTranslationUsageScanner;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
@@ -22,10 +22,12 @@ use Illuminate\Database\QueryException;
|
||||
* - seq 충돌 시 재시도 (unique 제약 위반 → seq 증가)
|
||||
* - 신규 키 생성 시 모든 활성 로케일에 폴백 시드
|
||||
* - 낙관적 잠금 (`lock_version` — update 경로)
|
||||
* - 커스텀 키 CRUD 시 다국어 캐시 무효화
|
||||
* - 커스텀 키 CRUD 시 다국어 캐시 무효화
|
||||
*/
|
||||
class TemplateCustomTranslationService
|
||||
{
|
||||
use ClearsTemplateCaches;
|
||||
|
||||
/**
|
||||
* seq 충돌 재시도 최대 횟수.
|
||||
*/
|
||||
@@ -33,11 +35,9 @@ class TemplateCustomTranslationService
|
||||
|
||||
/**
|
||||
* @param TemplateCustomTranslationRepositoryInterface $repository 커스텀 다국어 키 리포지토리
|
||||
* @param CacheInterface $cache 캐시 드라이버
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly TemplateCustomTranslationRepositoryInterface $repository,
|
||||
private readonly CacheInterface $cache,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -287,11 +287,12 @@ class TemplateCustomTranslationService
|
||||
*
|
||||
* `serveLanguage` 캐시 키가 `template.language.{id}.{locale}.v{cacheVersion}`
|
||||
* 형태로 `ext.cache_version` 을 포함하므로, 이 값을 갱신하면 다음
|
||||
* `loadTranslations` 가 재fetch 합니다.
|
||||
* `loadTranslations` 가 재fetch 합니다. 쓰기는 트레이트 단일 지점
|
||||
* (고정 CoreCacheDriver + 메모이즈 스토어) 경유.
|
||||
*/
|
||||
private function invalidateLanguageCache(): void
|
||||
{
|
||||
$this->cache->put('ext.cache_version', time());
|
||||
$this->incrementExtensionCacheVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user