diff --git a/plugins/system/cache/cache.php b/plugins/system/cache/cache.php index 2c210c50cf5db..fc55b7ce80e1e 100644 --- a/plugins/system/cache/cache.php +++ b/plugins/system/cache/cache.php @@ -104,7 +104,7 @@ protected function getCacheKey() */ public function onAfterInitialise() { - if ($this->app->isClient('administrator') || $this->app->get('offline', '0') || count($this->app->getMessageQueue())) + if ($this->app->isClient('administrator') || $this->app->get('offline', '0') || $this->app->getMessageQueue()) { return; } @@ -114,9 +114,8 @@ public function onAfterInitialise() $results = JEventDispatcher::getInstance()->trigger('onPageCacheSetCaching'); $caching = !in_array(false, $results, true); - $user = JFactory::getUser(); - if ($caching && $user->get('guest') && $this->app->input->getMethod() == 'GET') + if ($caching && JFactory::getUser()->guest && $this->app->input->getMethod() === 'GET') { $this->_cache->setCaching(true); } @@ -130,7 +129,7 @@ public function onAfterInitialise() $this->app->setBody($data); // Dumps HTML page. - echo $this->app->toString(); + echo $this->app->toString((bool) $this->app->get('gzip')); // Mark afterCache in debug and run debug onAfterRespond events. // e.g., show Joomla Debug Console if debug is active. @@ -146,25 +145,31 @@ public function onAfterInitialise() } /** - * After Route Event. + * After Render Event. * Verify if current page is not excluded from cache. * * @return void * - * @since 3.9.0 + * @since __DEPLOY_VERSION__ */ - public function onAfterRoute() + public function onAfterRender() { - if ($this->app->isClient('administrator') || $this->app->get('offline', '0') || count($this->app->getMessageQueue())) + if ($this->_cache->getCaching() === false) { return; } + // We need to check if user is guest again here, because auto-login plugins have not been fired before the first aid check. // Page is excluded if excluded in plugin settings. - if ($this->isExcluded()) + if (!JFactory::getUser()->guest || $this->app->getMessageQueue() || $this->isExcluded() === true) { $this->_cache->setCaching(false); + + return; } + + // Disable compression before caching the page. + $this->app->set('gzip', false); } /** @@ -177,17 +182,13 @@ public function onAfterRoute() */ public function onAfterRespond() { - if ($this->app->isClient('administrator') || $this->app->get('offline', '0') || count($this->app->getMessageQueue())) + if ($this->_cache->getCaching() === false) { return; } - // We need to check if user is guest again here, because auto-login plugins have not been fired before the first aid check. - if (JFactory::getUser()->get('guest')) - { - // Saves current page in cache. - $this->_cache->store(null, $this->getCacheKey()); - } + // Saves current page in cache. + $this->_cache->store($this->app->getBody(), $this->getCacheKey()); } /** @@ -246,11 +247,6 @@ protected function isExcluded() $results = JEventDispatcher::getInstance()->trigger('onPageCacheIsExcluded'); - if (in_array(true, $results, true)) - { - return true; - } - - return false; + return in_array(true, $results, true); } }