缓存一个页面
test.php
Query($sql); $smarty->assign("car",$attr); $smarty->display("test.html"); //从内存缓存中获取页面代码 $content = ob_get_contents(); //将获取到的内容存放到缓存文件 file_put_contents($filename,$content); //清掉内存缓存 ob_flush(); echo "######################################";}else{ include($filename);}
test.html
汽车信息
代号 | 汽车名称 | 油耗 | 价格 |
<{ $v[0]}> | <{ $v[1]}> | <{ $v[4]}> | <{ $v[7]}> |
分页缓存
testa.php
StrQuery($szs); $page = new Page($zs,5); $xinxi = $page->fpage(); $sql = "select * from car ".$page->limit; $attr = $db->Query($sql); $smarty->assign("car",$attr); $smarty->assign("xinxi",$xinxi); $smarty->display("testa.html"); $nr = ob_get_contents(); file_put_contents($filename,$nr); ob_flush(); echo "################################################";}else{ include($filename);}
testa.heml
汽车信息
代号 | 汽车名称 | 油耗 | 价格 |
<{ $v[0]}> | <{ $v[1]}> | <{ $v[4]}> | <{ $v[7]}> |
<{ $xinxi}>