<?php
$filename = "../cache/test.html"; //缓存文件的地址
$youxiao = 3; //定义缓存有效期为3秒
//判断缓存文件是否存在
if(file_exists($filename) && (filemtime($filename)+$youxiao)>time()){
//如果存在,直接读取缓存文件
include($filename);
}else{
ob_start(); //开启内存缓存
require "../DBDA.class.php";
require "../init.inc.php";
$db = new DBDA();
$sql = "select * from info";
$arr = $db->query($sql);
$smarty->assign("shuju",$arr);
$smarty->display("test.html");
$str = ob_get_contents(); //获取内存中的静态页面
file_put_contents($filename,$str); //将获取到的内容写入到缓存文件
ob_flush(); //输出内存并且释放
echo "#####################################";
}