Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions plugins/system/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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.
Expand All @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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);
}
}