diff --git a/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php b/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php index 369c4056..be4cc50c 100644 --- a/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php +++ b/source/packages/plg_system_mokosuiteclient/Extension/MokoSuiteClient.php @@ -186,12 +186,15 @@ class MokoSuiteClient extends CMSPlugin implements BootableExtensionInterface */ public function onExtensionAfterSave($context, $table, $isNew) { + // Auto-clear cache on any extension save (#181) + $this->autoClearCache(); + if ($context !== 'com_plugins.plugin') { return; } - // Only act on our own plugin + // Only act on our own plugin for the rest of this handler if ($table->element !== 'mokosuiteclient' || $table->folder !== 'system') { return; @@ -2522,6 +2525,9 @@ class MokoSuiteClient extends CMSPlugin implements BootableExtensionInterface */ public function onContentAfterSave($context, $article, $isNew): void { + // Auto-clear cache on content save (#181) + $this->autoClearCache(); + if ($context !== 'com_content.article') return; class_exists(\Moko\Component\MokoSuiteClient\Administrator\Service\AutomationEngine::class, true) && \Moko\Component\MokoSuiteClient\Administrator\Service\AutomationEngine::fire('content_save', [ @@ -2863,4 +2869,39 @@ class MokoSuiteClient extends CMSPlugin implements BootableExtensionInterface return null; } } + + // ------------------------------------------------------------------ + // Cache Auto-Clear (#181) + // ------------------------------------------------------------------ + + /** + * Clear all Joomla cache groups when the auto_clear_cache param is enabled. + * + * Called from onContentAfterSave and onExtensionAfterSave so that + * front-end visitors always see fresh content after an admin save. + * + * @return void + * + * @since 02.47.50 + */ + private function autoClearCache(): void + { + if (!$this->params->get('auto_clear_cache', 0)) + { + return; + } + + try + { + $cacheController = \Joomla\CMS\Cache\Cache::getInstance('', ['defaultgroup' => '']); + $cacheController->clean(''); + + Log::add('Cache auto-cleared on save.', Log::DEBUG, 'mokosuiteclient'); + } + catch (\Throwable $e) + { + // Silent — never break save operations + Log::add('Cache auto-clear failed: ' . $e->getMessage(), Log::WARNING, 'mokosuiteclient'); + } + } } diff --git a/source/packages/plg_system_mokosuiteclient/mokosuiteclient.xml b/source/packages/plg_system_mokosuiteclient/mokosuiteclient.xml index d63b53a1..2dc5f13a 100644 --- a/source/packages/plg_system_mokosuiteclient/mokosuiteclient.xml +++ b/source/packages/plg_system_mokosuiteclient/mokosuiteclient.xml @@ -99,7 +99,15 @@ description="PLG_SYSTEM_MOKOSUITECLIENT_MONITOR_BASE_URL_DESC" filter="url" /> - + + + + +