Filepath: phork/php/hooks/CacheHooks.class.php

The CacheHooks class is collection of hooks to serve and save page caches. It's called from the bootstrap.

In order for pages to be cached, the output buffer must be turned on in the display object. The URLs to cache should be defined as regular expression patterns in the site configuration files. This caches complete pages, so if any part of the page contains a username or any data that changes on a per-user basis either this shouldn't be used, or the namespace should be used. In cases like that it's possible to cache page nodes using the CoreController class.

This requires a caching object in the registry with the name Cache.

Site Config Example

//cache all pages of the manual for 300 seconds
$arrConfig['CacheUrls'] = array(
    '|(/manual/[^/]+/[^/]+/)|' => array(
        'Namespace' => null,
        'Expire' => 300

Usage Example (from the bootstrap)

//add the hooks to handle full page caching
if (AppLoader::includeHooks('CacheHooks')) {
    $objCacheHooks = new CacheHooks();
    $this->registerPreRunHook(array($objCacheHooks, 'serveCache'));
    $this->registerPostRunHook(array($objCacheHooks, 'saveCache'));