2.1.2releasedCacheLite

Simple frontend output caching with CacheLite.

Clone URLhttps://github.com/symphonists/cachelite.git

Add as a submodulegit submodule add https://github.com/symphonists/cachelite.git extensions/cachelite --recursive

Compatibility

2.x.x2.1.x2.2.x2.3.x2.4.x2.5.x2.6.x2.7.02.7.12.7.22.7.32.7.42.7.52.7.62.7.72.7.82.7.92.7.10
No1.0.9No1.3.31.3.31.3.32.1.22.1.22.1.22.1.22.1.22.1.22.1.22.1.22.1.22.1.22.1.22.1.2

Readme

CacheLite

Installation

  1. Upload the 'cachelite' folder in this archive to your Symphony 'extensions' folder.
  2. Enable it by selecting the "CacheLite", choose Enable from the with-selected menu, then click Apply.
  3. Go to System > Preferences and enter the cache period (in seconds).
  4. The output of your site will now be cached.

Usage

Excluding pages

By default all pages are cached. You can exclude URLs from the cache by adding them to the list of excluded pages in System > Preferences. Each URL must sit on a separate line and wildcards (*) may be used at the end of URLs to match everything below that URL.

Excluded pages are assumed to originate from the root. All the following examples will resolve to the same page (providing there are none below it in the hierarchy):

/about-us/get-in-touch/*
http://root.com/about-us/get-in-touch/
about-us/get-in-touch*
/about-us/get*

Note that caching is not done for logged in users. This lets you add administrative tools to the frontend of your site without them being cached for normal users.

Flushing the cache

Caching is done on a per-URL basis. To manually flush the cache for an individual page simply append ?flush to the end of its URL. To flush the cache for the entire site you just need to append ?flush=site to any URL in the site. You must be logged in to flush the cache.

You can also remove cache files using your FTP client: navigate to /manifest/cache and remove the files named as cache_{hash}.

The cache of each page will automatically flush itself after the timeout period is reached. The timeout period can be modified on the System > Preferences page.

Flushing the cache when content changes

You can selectively flush the cache when new entries are created or an entry is updated. Updates through both the backend and frontend Events are supported. To flush the cache when entries are modified in the Symphony backend navigate to System > Preferences and tick the "Expire cache when entries are created/updated through the backend?" checkbox. When an entry is modified, one of two outcomes are achieved:

a) When a brand new entry is created, the cache will be flushed for any pages that show entries from the entry's parent section.
For example if you have an Articles section which is used to display a list of recent article titles on the Home page; a list of articles on an Articles Index page; and another page to read an Article; the cache of all three pages will be flushed when a new Article entry is created.

b) When an existing entry is edited, the cache will be flushed for any pages that display this entry.
In the above example, if the article being edited is very old and no longer features on the Home page or Articles Index page, only the specific instance of the Aricle view page for this entry will be flushed. Other Article view pages remain cached.

The same conditions are provided for frontend Events through the use of Event Filters. To add this functionality to your event, select one or all of the CacheLite event filters when configuring your event and trigger them using values in your HTML form:

a) "CacheLite: expire cache for pages showing this entry"
When editing existing entries (one or many, supports the Allow Multiple option) any pages showing this entry will be flushed. Send the following in your form to trigger this filter:

<input type="hidden" name="cachelite[flush-entry]" value="yes"/>

b) CacheLite: expire cache for pages showing content from this section
This will flush the cache of pages using any entries from this event's section. Since you may want to only run it when creating new entries, this will only run if you pass a specific field in your HTML:

<input type="hidden" name="cachelite[flush-section]" value="yes"/>

c) CacheLite: expire cache for the passed URL

This allows you to selectively flush the cache during Event execution, which is useful if you want to expire the cache as new entries are added but don't want to flush the whole section. This filter will only run if you pass a specific field in your HTML:

<input type="hidden" name="cachelite[flush-url]" value="/article/123/"/>

If you pass this field with no value, it will default to the current URL. That is, from a page at http://domain.tld/article/123/, submitting the following:

<input type="hidden" name="cachelite[flush-url]"/>

Would have the same result as the previous example.

Large websites

Deleting lots of cache entries may make the backend slow. If you feel like you are waiting too long for entries to save, it may be because deleting files on disk is slow. You can change the cache invalidation strategy and use a cron job to purge the cache. You first need to manually edit your config.php file, to set the 'clean-strategy' value to 'cron'

###### CACHELITE ######
'cachelite' => array(
    ...
    'clean-strategy' => 'cron',
),
########

Then, your need to configure the cron job that will purge the cache in the background, at every 5 minutes

*/5 * * * * php /path/to/website/extensions/cachelite/cron/delete_invalid.php

Bypassing the cache

Extensions can tell cachelite to bypass the cache on particular requests. Extensions must implement the CacheliteBypass delegate.

The delegate is as follows:

php /** * Allows extensions to make this request * bypass the cache. * * @delegate CacheliteBypass * @since 2.0.0 * @param string $context * '/frontend/' * @param bool $bypass * A flag to tell if the user is logged in and cache must be disabled */ Symphony::ExtensionManager()->notifyMembers('CacheliteBypass', '/frontend/', array( 'bypass' => &$cachebypass, ));

By changing the value of $context['bypass'] to true the request will not use the cache.

Version history

Symphony 2.6.x to 2.x.x

  • Fix crash on deleting entries

Symphony 2.6.x to 2.x.x

  • Fix 2.1.0 release notes

Symphony 2.6.x to 2.x.x

  • Add a cron cache purge strategy

Symphony 2.6.x to 2.x.x

  • Fix issue where the root page was always excluded from cache (#38)

Symphony 2.6.x to 2.x.x

  • Fix issue on MySQL 5.5 (#37)

Symphony 2.6.x to 2.x.x

  • Tidy up code style
  • Refactored the database to make it more scalable (#36)
  • Added the CacheliteBypass delegate (#30)
  • Refactored the http headers (#27)

Symphony 2.3.x to 2.x.x

  • Fixed an issue with Excluding pages

Symphony 2.3.x to 2.x.x

  • Fixed an issue when the page xml is not valid

Symphony 2.3.x to 2.x.x

  • Updated compatibility infos

Symphony 2.3.x to 2.5.x

  • Fixed some issues (#9, #20, #22)
  • Support for Symphony 2.5

Requires Symphony 2.3.x

  • Compatible with Symphony 2.3
  • Updated cachelite library to most recent version 1.7.12

Requires Symphony 2.1.0

  • Don't cache is there is $_POST data

Requires Symphony 2.1.0

  • Romanian translation from vlad-ghita
  • Check context is set before clear

Requires Symphony 2.1.0

  • Fix bug in excluded pages introduced by change in 1.1.0

Requires Symphony 2.1.0

  • Fix bug in ?flush
  • Made sure $_GET parameters are parsed consistently (i.e., regardless of order)

Requires Symphony 2.1.0

  • Encode URLs

Requires Symphony 2.1.0

  • Removed references to Frontend
  • Cleaned up accessors

Requires Symphony 2.1.0

  • Added support additional content types via the Content Type Mappings extension

Requires Symphony 2.1.0

  • Added 304 header support

Requires Symphony 2.1.0

  • Localisation and italian translation from eKoeS

Requires Symphony 2.1.0

  • Minor cleanup to use newer accessors for Administration/Symphony instances

Requires Symphony 2.1.0

  • Added functions for translation
  • Fixed matching on page ?flush
  • Defaults for configuration

Requires Symphony 2.1.0

  • Changed intercept_page delegate to FrontendPageResolved. Should now execute immediately after the Page is found, but before anything else happens.
  • Because of the change above, headers are determined manually (as with normal pages). Supported types are HTML, XML and JSON.

Requires Symphony 2.1.0

  • Added support for flushing the cache on a per-URL basis during Event execution

Requires Symphony 2.1.0

  • Subscribe to the Delete delegate to flush pages when an entry is removed (delegate not included in Symphony 2.0.6) (Nick Dunn)
  • Fixed bug introduced in 1.0.2 where caching was occurring for logged in users
  • Fixed bug introduced in 1.0.2 where ?flush was being included in the cache ID

Requires Symphony 2.1.0

  • Added support for flushing the cache based on entry/section I