ModelCache

Filepath: phork/php/ext/helpers/ModelCache.class.php

The ModelCache class is an extension of the CoreModelHelper class that's used to load data from the cache and save it back to the cache if the cache load failed.

The cache helper has a preLoad event method that attempts to load the data from the cache, and a postLoad event method that saves the data back to the cache. One can be initialized without the other.


Run Time Example

//set up the cache helper to attempt to load the data from the cache and to recache on failure
AppLoader::includeExtension('helpers/', 'ModelCache');
$objUser->appendHelper('cache', 'ModelCache');
$objUser->initHelper('cache', array('preLoad', 'postLoad'), array('Namespace' => 'test', 'Expire' => 60));

if ($objUser->load(array('Limit' => 2), true)) {
    while (list(, $objRecord) = $objUser->each()) {
        print 'username = ' . $objRecord->get('username') . '<br />';
    }
}

//destroy the cache helper otherwise it will be applied to subsequent object loads
$objUser->destroyHelper('cache');