<?php
 
/**
 
* This example represents how easily we can automate 
 
* caching of both news list, and single news using 
 
* CacheManager class
 
*/
 
 
function GetElement ($key) {
 
    /* return single news */
 
    return 'Full News Number '.$key;
 
}
 
 
function GetElements () {
 
    /* return news list */
 
    for ($i=1; $i<11; $i++) $result .= '<a href="./?id='.$i.'">News '.$i.'</a><br/ >';
 
    return $result;
 
}
 
 
include './cachemanager.php';
 
 
$key = (isset($_GET['id']) ? intval($_GET['id']) : 0);
 
$CacheManager = &new CacheManager (0, 5);
 
$CacheManager->_cacheRoot = './cache/';
 
$content = $CacheManager->CheckCache ('news', $key);
 
if (!$content) {
 
    $content = ($key ? GetElement ($key) : $this->GetElements());
 
    $CacheManager->SaveToCache ('news', $key, $content);
 
}
 
 
echo $content;
 
?>
 
 |