PHP Smarty Cache

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.