Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexander Stepanenko  >  CacheManager  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: CacheManager
Cache arbitrary data in files
Author: By
Last change:
Date: 2006-02-01 03:29
Size: 798 bytes
 

Contents

Class file image Download
<?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 (05);
$CacheManager->_cacheRoot './cache/';
$content $CacheManager->CheckCache ('news'$key);
if (!
$content) {
    
$content = ($key GetElement ($key) : $this->GetElements());
    
$CacheManager->SaveToCache ('news'$key$content);
}

echo 
$content;
?>