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', [
|
||||
|
||||
Reference in new issue
Block a user