Skip to main content

The cache system (v2)

Tuskfish has separate systems for caching images and pages, which reduce load on the server by "saving" content that has been dynamically generated for repeat viewing. Page-level caching can be enabled or disabled via the site preferences.

Image cache

When you upload an image with a content object (the 'image' field on the data entry form) you should provide a high quality image at or slightly above the maximum size you ever expect to display it. Think of it as a master image; you will not use it directly in your site, but you can use it to make copies for different purposes.

Typically you will need to display this image at different sizes in different areas of your site. For example, as a thumbnail accompanying a content teaser on your home page, and at a larger size when the full description of the content is viewed.

When a page is requested, Tuskfish checks the image cache folder (site_root/cache) to see if thumbnails matching the dimensions specified in the template already exist. If so, those are inserted into the template, and if not, Tuskfish will generate a thumbnail and save it to the cache for re-use on subsequent page loads.

The size of thumbnails is actually specified in the theme/template files by making a call to an object's cachedImage() method. In the example below a 300px wide thumbnail of an object's master image will be inserted into the template:

<img src="<?php echo $content->cachedImage(300); ?>" alt="<?php echo $content->caption(); ?>" />

On another page you might want to display the same image at 600px wide, in which case you would use:

<img src="<?php echo $content->cachedImage(600); ?>" alt="<?php echo $content->caption(); ?>" />

If you change the layout of your site later on you may need to display content images at different sizes. Simply change the size of the thumbnails specified in the relevant theme/template files and your site will automatically build new thumbnails and update itself. Cool, huh?

Page cache

The page caching system works on similar principles to the image caching system. When a page is requested the controller script first checks if a cached copy exists. If so the script returns the cached version and stops executing, and if not execution continues to make the page and save it in the cache for re-use.

Cached pages are stored in a different location to images, in trust_path/cache. This is to ensure that people can't directly access cached pages via their browser, in case a page has been marked offline.

You can clear the page cache by clicking the Flush cache link in the admin section of your site (it does not clear the image cache). The cache will automatically be flushed every time you add, edit or delete a content object, to ensure that your index pages always remain up to date. You should not cache back end administrative pages.

Copyright, all rights reserved.