Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c0cc772f4c
Fetching contributors…

Cannot retrieve contributors at this time

129 lines (76 sloc) 6.031 kb

Cache

Cache is a module for ExpressionEngine that creates static HTML files from parsed templates. It improves performance by removing the need to run the template parser on each URI request.

Requires ExpressionEngine 2.4.0 or later

Installation & Usage

  1. In addition to the normal module installation procedure you will also need to create a directory when the static files will be placed. The module is set to use /cache, in your base directory, by default.

  2. Go to the Settings module page to configure the module settings. Find details on these settings below.

  3. Copy the rewrite rules from the Rewrite module page to your .htaccess file.

Module Pages

Cached

This page contains a table of cached URIs.

  • URI - The URI that was cached.

  • Type - The type of page that was cached; Web Page, 404 or Redirect.

  • Templates - The number of templates associated with the cached URI.

  • Entries - The number of entries associated with the cached URI.

  • Cached - A fuzzy relative date to give you an idea of when the URI was cached. Hover over this for a second to see a more accurate timestamp.

Clear

Provides a helpful form that allows clearing of any static files based on their URI pattern or age.

Rewrite

Generates rewrite rules based on your settings. This can be copied into your .htaccess file.

These rules are intended to compliment your existing rules, however it’s impossible to make it compatible with every system and rule set out there.

The rules are set up to check the existence of static files for the supplied URI. If this file exists then that file will be delivered to the client. If it does not exist then the URI is routed to ExpressionEngine where the static file will be generated at the end of the template parsing process.

Settings

  • Cache Path - The server path to the chosen static files directory. By default this will be /cache.

  • Cache URL (Relative) - The URL where the static files are located. This can be relative to your domain and is set to /cache/ by default.

  • Clear when editing entries - If active this will clear any static files that are associated with the entry being modified.

  • Clear when editing templates - If active this will clear any static files that are associated with the modified template.

  • Cache 404s - Creates a PHP file with the correct headers. This is an experimental feature and may be removed in a future update.

  • Cache redirects - Creates a PHP file with the correct headers. This is an experimental feature and may be removed in a future update.

Module Tags

disable

Disables the module from caching the current URI.

{exp:cache:disable}

link_entry

Links an entry to the current URI. By default the module will record any entries that are output using the {exp:channel:entries} tag or other modules that use the Channel module as a base (f.ex. Playa). If you find an instance where this is not the case you can use this tag.

{exp:cache:link_entry entry_id="{entry_id}"}
{exp:cache:link_entry entry_id="10|27"}

clear

If you want to programmatically clear the cached files you can do so using this tag. There are several parameters to filter the URIs that are cleared, which are listed below.

  • older_than - Older than the specified number of seconds.

  • newer_than - Younger than the specified number of seconds.

  • pattern - Matches the supplied REGEX pattern. You are may also use the CodeIgniter route shortcuts :any and :num.

  • uri - Matches the supplied URI string.

  • entry_id - Associated with one or more of the supplied entry IDs.

  • template_id - Associated with one or more of the supplied entry IDs.

{exp:cache:clear older_than="86400"} {!-- Older than one day --}
{exp:cache:clear older_than="604800" newer_than="1209600"} {!-- One week prior --}
{exp:cache:clear uri="/"} {!-- The homepage --}
{exp:cache:clear pattern="/blog:any"} {!-- All blog URIs --}

Config Overriding

It’s possible to override the module configuration using the /system/expressionengine/config/config.php file. This allows different configurations for different environments.

<?php // Cache module configuration
$config['cache_path']                     = '/my_server_path/cache/';
$config['cache_url']                      = '/cache/';
$config['cache_404']                      = 'y';
$config['cache_redirect']                 = 'y';
$config['cache_clear_on_entry_edit']      = 'y';
$config['cache_clear_on_template_edit']   = 'y';
$config['cache_clear_on_global_var_edit'] = 'y';
$config['cache_clear_on_snippet_edit']    = 'y';
$config['cache_enabled']                  = 'y';
?>

Caveats

A hardcoded limit of 1000 is imposed on batch clearing methods. This affects the form on the Clear module page and the clear tag.

Copyright and License

Copyright (C) 2012 Joshua Baker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Jump to Line
Something went wrong with that request. Please try again.