test.php
<?PHP//define the path where the page cache file is stored$filename= ".. /cache/cachetest.html ";//Defining cache validity periods$cachetime= 5;//determine if the cache file existsif(!file_exists($filename) ||Filemtime($filename)+$cachetime< Time()){ //Open Memory Cache Ob_start(); include(".. /init.inc.php "); include(".. /dbda.php "); $db=NewDbda (); $sql= "SELECT * FROM Car"; $attr=$db->query ($sql); $smarty->assign ("Car",$attr); $smarty->display ("test.html"); //get the page code from the in-memory cache $content=ob_get_contents(); //Store the acquired content in the cache file file_put_contents($filename,$content); //clear out the memory cache Ob_flush(); Echo"######################################";}Else{ include($filename);}
Test.html
<body>foreach$caras$v}> <tr> <td><{$v[0]}></td> <td><{$v[1]}></ td> <td><{$v[4]}></td> <td><{$v[7]}></td > </tr> <{/foreach}> </table></body>
Paged Cache
testa.php
<?PHP//Fetch Current Page$p=1;if(!Empty($_get["Page"])){ $p=$_get["Page"];}//defining cache file Storage Paths$filename= ".. /cache/cahetesta{$p}.html ";//Judgingif(!file_exists($filename) ||Filemtime($filename) +30< Time()){ Ob_start(); include(".. /init.inc.php "); include(".. /dbda.php "); $db=NewDbda (); include("page.class.php"); $szs= "SELECT count (*) from car"; $zs=$db->strquery ($szs); $page=NewPage ($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
<body>foreach$caras$v}> <tr> <td><{$v[0]}></td> <td><{$v[1]}></ td> <td><{$v[4]}></td> <td><{$v[7]}></td > </tr> <{/foreach}> </table><div><{$xinxi} ></div></body>
PHP Smarty Cache