/** * Clear caches * * @return void */ protected function clearCaches() { // remember settings before changes $jsCache = $this->applicationSetting('application_js_cache'); $jsCacheGzip = $this->applicationSetting('application_js_cache_gzip'); $cssCache = $this->applicationSetting('application_css_cache'); $cssCacheGzip = $this->applicationSetting('application_css_cache_gzip'); // clear js and css cache if needed $eventManager = ApplicationEvent::getEventManager(); $eventManager->attach(ApplicationEvent::CHANGE_SETTINGS, function ($e) use($jsCache, $jsCacheGzip, $cssCache, $cssCacheGzip) { // get post values $post = $this->getRequest()->getPost(); // clear js cache if ($jsCache != $post['application_js_cache'] || $jsCacheGzip != $post['application_js_cache_gzip']) { if (true === ($clearResult = CacheUtility::clearJsCache())) { ApplicationEvent::fireClearCacheEvent(self::CACHE_JS); } } // clear css cache if ($cssCache != $post['application_css_cache'] || $cssCacheGzip != $post['application_css_cache_gzip']) { if (true === ($clearResult = CacheUtility::clearCssCache())) { ApplicationEvent::fireClearCacheEvent(self::CACHE_CSS); } } // clear dymanic cache if (true === ($clearResult = CacheUtility::clearDynamicCache())) { ApplicationEvent::fireClearCacheEvent(self::CACHE_DYNAMIC); } }); }
/** * Settings */ public function settingsAction() { // clear a layout caches $eventManager = ApplicationEvent::getEventManager(); $eventManager->attach(ApplicationEvent::CHANGE_SETTINGS, function ($e) { $this->getModel()->clearLayoutCaches(); }); return new ViewModel(['settings_form' => parent::settingsForm('layout', 'layouts-administration', 'settings')]); }