Improve Performance With Caching

If your site is being hit hard then the built in caching system can help. It is completely configurable and supports caching of the entire rendered template, views, partials and images.

Currently only file based caching is supported in the framework.

To turn on caching you simply edit your app/config/config.yml file along with the app/config/production.php file.

Configuring The Cache

Out of the box the framework supports caching on layouts (layout_cache), views (view_cache) and partials (partial_cache).

In these examples we will use 'layout_cache'. This type of cache stores the entire rendered layout of the url you are visiting and can be loaded without the need for most of the framework files, making it even faster.

All cache configurations use the same syntax and structure:

layout_cache:
  engine: "File"
  exclude_post: "no"  

To increase duration of the cache you can set life time of the cache:

layout_cache:
  lifetime: 36000
  engine: "File"
  exclude_post: "no"  

White and Black Listing

The cache system also supports regular expression based includes and exclude options. This way you can either cache only certain pages (archives etc that don't change) or exclude pages that you always want to be up to date (live feed data etc).

This is very simple to do and is applied on a per cache basis (so layout cache can exclude certain pages that view cache includes).

layout_cache:
  lifetime: 36000
  engine: "File"
  exclude_post: "no"
  exclusions:
    contact: "/contact/i"
    admin: "/admin/i"
layout_cache:
  lifetime: 36000
  engine: "File"
  exclude_post: "no"
  inclusions:
    contact: "/contact/i"
    admin: "/admin/i"

More Override Control

If the regular expressions aren't enough and you need to be able to turn cache on or off in your controller based upon certain logic / query outcomes that is also possible.

Say you have you want to turn off caching if a certain session value is present (such as a logged in user flag) you can use the use_cache property:

public function test() {
  if(Session::get('user_logged_in') == 1) $this->use_cache = false;
}

This will force caching to be turned off for this page (as long as the page has not been called directly from the cache).