I found this on codingforums
<?php
class cache
{
var $cache_dir = 'templet/cache/';//This is the directory where the cache files will be stored;
var $cache_time = 100;//How much time will keep the cache files in seconds.
var $caching = false;
var $file = '';
function cache()
{
//Constructor of the class
clearstatcache();
$this->file = $this->cache_dir . urlencode( $_SERVER['REQUEST_URI'] );
if ( file_exists ( $this->file ) && ( filectime ( $this->file ) + $this->cache_time ) > time() )
{
//Grab the cache:
$handle = fopen( $this->file , "r");
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
echo $data;
} while (true);
fclose($handle);
}
else
{
//create cache :
$this->caching = true;
ob_start();
}
}
function close()
{
//You should have this at the end of each page
if ( $this->caching )
{
//You were caching the contents so display them, and write the cache file
$data = ob_get_clean();
echo $data;
$fp = fopen( $this->file , 'w' );
fwrite ( $fp , $data );
fclose ( $fp );
}
}
?>
to use it on a page I use
<?
$a = new cache();
if ( $a->caching )
{
all my code here to cache to file
}
$a->close();
?>
?>
What I want to do though is modify it to allow me to include this cache file into many pages and set the time to save the file through the fucntion
var $cache_time = 100;//How much time will keep the cache files in seconds.
so maybe it would work like this
<?
$a = new cache($time); /// make where I can set the time variable
if ( $a->caching )
{
//INSTEAD OF
$a = new cache();
if ( $a->caching )
{
?>