CacheCracker Extension
CacheCracker is an extension to give you complete control over caching in your ExpressionEngine system. It is designed to be installed at any time, including when first starting development on a new project, giving development and your production site a potentially massive speed boost.
Features
CacheCracker has the following features:
- Forced caching for all templates, or selected template groups
-
Expires cache files for individual templates when editing from the filesystem
Normally, EE runs embeds on each page they are included on and caches the results only for that page. This feature helps EE out by sharing the first cached output for embeds between all pages that use them.
- Shared global caching - run global embeds only once (headers, footers, menu trees, etc.)
-
Late global parsing
Normally, segment variables, members vars and other globals are stored in the cached version of a page and are not re-parsed. This feature allows templates to be cached which make use of global variables through a new syntax.
- Expire caches on publishing content
CacheCracker Documentation
Functionality
- Global
- Forced Caching
- Expire on Editing Templates
- Expire on Content Publish
- Shared Global Caching
- Late Global Parsing
- Optional Core Hack
Global
The following settings are applied globally to CacheCracker.
Settings
- Turn on CacheCracker? - set to Yes to enable CacheCracker. Set to No to disable CacheCracker and disable caching for all templates on the site.
Forced Caching
Forced caching is designed to allow you to quickly setup global cache settings for all of the templates on your site. You can also optionally select only specific template groups to force caching on. It's a good idea to turn on this setting when first setting up a new site, to make sure that all newly created templates are automatically cached with your global settings.
If you do not want to cache certain templates, you can use a combination of the Force caching for template groups option and the normal Design > Templates > Template Preferences manager to turn on caching only for individual templates.
We recommend keeping templates that cannot be cached in a common group or groups so all other templates can be more easily cached. Normally, for instance, you would not want to cache a forms template group or a account template group since these contain information specific to a session or user.
Settings
- Force caching - set to Yes to turn on the forced caching feature.
- Forced refresh time (minutes) - default value to set as the refresh timeout for all templates. The default value for this setting is 5256000, which is the number of minutes in 10 years. Note that sites with active content or templates will not really have their templates cached this long.
- Force caching for template groups - template groups to force caching for. Defaults to "all". Select the groups you would like to force the above settings to be applied to automatically. On each page load, these settings will be reapplied to the selected groups.
Expire on Editing Templates
Cache files can be automatically reset when templates are edited in the filesystem. ExpressionEngine does not by default reset cache files when template files are edited.
Settings
- Expire caches when editing a template - set to Yes to enable this feature.
- Template checks only in debug mode - set to Yes to only check for template changes when the DEBUG config value is not 0. Recommended to avoid a small performance penalty on production sites that will not have their templates edited.
Expire on Content Publish
This feature automatically resets cache files when needed to immediately show published content on the live site. It is recommended that you make use of the Channel Settings options to only clear the templates that actually make use of specific channel data. You can also have all cache files reset on every publish, however this will drastically reduce the performance of your site when editing content.
Settings
- Expire caches when publishing content - set to Yes to enable this feature.
- Expire all caches on every publish (ignore channel settings) - forced all cache files to be reset when any content is published.
- Channel Settings - allows you to select - for each channel - which templates in each template group to reset when content is published in that channel.
Shared Global Caching
By default, ExpressionEngine always runs each embed template for each URL on the site, and caches the results only for that URL. This is a huge performance issue with complex headers, footers, menus, or other embedded templates that are identical (or nearly identical) on every execution.
Shared Global Caching automatically copies or symlinks these cached results into all other pages that make use of them to prevent these expensive embeds from running more than once.
When using this option you must use complex conditionals on most global variables, otherwise the results of the conditional will be cached, which is likely not what you want.
One easy way to make a conditional "complex" is simply to place parenthesis around it's expression, like so:
{if (segment_1 == 'about-us')} ... {/if}
If you would like to use segment or global variables in template output, see the next section for Late Global Parsing.
Activating
- To activate this option for a specific template, navigate to the edit form for a template in Design > Templates > Template Manager, and set the option Global Caching? to Yes under the template's Preferences section.
Settings
- Use symlinks for global template caches - uses symlinks instead of copies of shared cache files. This can reduce disk use somewhat, although it does not work correctly on all systems. Note that turning this option off uses exactly the same amount of space as normal ExpressionEngine caching, so it is not by any means necessary to use symlinks if normal caching's disk usage is acceptable.
Late Global Parsing
Normally, segment variables, members vars and other globals are stored in the cached version of a page and are not re-parsed. Using this new syntax allows you to use these variables in cached templates and still get the current value substituted, rather than whatever the value was when the template originally ran.
Mainly used in combination with the Shared Global Caching feature, this feature provides a new syntax that allows global variables to be used in output of cached templates.
The new syntax has this format:
{#variable_name#}
This feature requires the free Wallace extension.
Settings
- Add late global vars parsing - turns on this feature.
- Exclude late parsing for variables with these prefixes - exclude certain groups of variables to increase performance when they are not needed for late substitution. On a site with many pages, you may want to add at least the page_url: prefix to be ignored if you are using Wyvern.
Optional Core Hack
The optional core hack can be applied to fix issues when using caching in combination with the Structure or Uhura modules. These modules modify the segments array used by EE to create cache directories for each URL. Because of this, two issues can arise:
-
In Structure, any page that makes use of pagination segments (/P10/ for instance) will not be cached correctly. Instead of seeing each page of content, the first page requested (usually the very first page of the pagination) will be returned for all requests, no matter what P value is sent through the URL.
-
In Uhura, all caches will be shared between languages. This is obviously not desired since these different URLs will have very different content.
Applying the core hack is easy, simply follow these steps:
- Find the file system/expressionengine/libraries/Core.php.
- Find the line that reads require APPPATH.'libraries/Template.php'; (in the current version this is on line 609).
- Replace the require line and the following line that includes new EE_Template() with the following lines:
// BEING CacheCracker modification require_once PATH_THIRD.'cache_cracker/libraries/CC_Template.php'; $this->EE->TMPL = new CC_Template(); // END CacheCracker modification
After making this change, test your site well to confirm that all is well.