Skip to content

Commit

Permalink
Add (rudimentary) page exclusion support for the "System - Page Cache…
Browse files Browse the repository at this point in the history
…" plugin
  • Loading branch information
OctavianC committed Aug 25, 2015
1 parent 095c4a1 commit 399c559
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.plg_system_cache.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

PLG_CACHE_FIELD_BROWSERCACHE_DESC="If yes, use mechanism for storing page cache in the browser."
PLG_CACHE_FIELD_BROWSERCACHE_LABEL="Use Browser Caching"
PLG_CACHE_FIELD_EXCLUDE_DESC="Specify which pages you wish to exclude from caching, each on a separate line. Regular expressions are supported."
PLG_CACHE_FIELD_EXCLUDE_LABEL="Exclude Pages"
PLG_CACHE_FIELD_LIFETIME_DESC="Page cache lifetime in minutes."
PLG_CACHE_FIELD_LIFETIME_LABEL="Cache Lifetime"
PLG_CACHE_XML_DESCRIPTION="Provides page caching."
Expand Down
29 changes: 28 additions & 1 deletion plugins/system/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,37 @@ public function onAfterRender()

$user = JFactory::getUser();

if ($user->get('guest'))
if ($user->get('guest') && !$this->isExcluded())
{
// We need to check again here, because auto-login plugins have not been fired before the first aid check.
$this->_cache->store(null, $this->_cache_key);
}
}

protected function isExcluded() {
if ($exclusions = $this->params->get('exclude', '')) {
// Normalize line endings
$exclusions = str_replace(array("\r\n", "\r"), "\n", $exclusions);

// Split them
$exclusions = explode("\n", $exclusions);

// Get current path to match against
$path = JUri::getInstance()->toString(array('path', 'query', 'fragment'));

// Loop through each pattern
if ($exclusions) {
foreach ($exclusions as $exclusion) {
// Make sure the exclusion has some content
if (strlen($exclusion)) {
if (preg_match('/'.$exclusion.'/is', $path, $match)) {
return true;
}
}
}
}
}

return false;
}
}
6 changes: 6 additions & 0 deletions plugins/system/cache/cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="exclude" type="textarea"
filter="raw"
default=""
description="PLG_CACHE_FIELD_EXCLUDE_DESC"
label="PLG_CACHE_FIELD_EXCLUDE_LABEL"
/>
</fieldset>
</fields>
</config>
Expand Down

0 comments on commit 399c559

Please sign in to comment.