<?
/*ftbbs缓存类文件
* 使用方法(删除缓存文件触发更新缓存)：
*
*       include('cacheclass.php');//必须在文件最开始处包含本页
*       $cache = new ftbbscache($cachefile,$time);//设置缓存文件和缓存时间
*       ……
*       ……
*       ……//代码
*       $cache->endcache();//在文件最后写入
*/
ob_start();
class ftbbscache
{
  function ftbbscache($cachefile,$time)
  {
  $this->time     = $time;
  $this->filename = $cachefile;
  if (file_exists($this->filename) && ((filemtime($this->filename)+$this->time) > time()))
  {
    $fp = fopen($this->filename,"r");
    echo fread($fp,filesize($this->filename));
    fclose($fp);
    ob_end_flush();
    exit;
  }
 }
//在文件最后加入这行，输出所有缓存内容，并且写入缓存文件。
 function endcache()
 {
  $fp = fopen($this->filename,"w");
  fwrite($fp,ob_get_contents());
  fclose($fp);
  ob_end_flush();
 }
}
//end class
?>