zoukankan      html  css  js  c++  java
  • smarty缓存

    huancun.php代码

    <?php
    $p =1;
    if( !empty($_GET["page"]))
    {
    $p =$_GET["page"];
    }
    $filename="../../cache/huancun{$p}.html";//缓存文件存放的位置
    //判断缓存文件是否存在,如果存在直接调用,没有没有重新缓存。
    $time=30;//缓存时间10秒

    if(file_exists($filename) && (filemtime($filename)+$time >= time()))
    {
    //直接调用缓存

    include("$filename");

    }
    else
    {
    ob_start();//开启内存缓存
    include("../../init.inc.php");
    include("../../DBDA.class.php");
    $db=new DBDA();
    $sall=" select count(*) from course ";
    $zts =$db->StrQuery($sall);


    include("../../page.class.php");
    $page =new Page($zts,5);


    $sql="select * from course ".$page->limit;
    $arr =$db->Query($sql);
    $smarty->assign("fpage",$page->fpage());
    $smarty->assign("shuzu",$arr);
    $smarty->display("huancun.html");

    $str=ob_get_contents();//获取内存中的内容
    file_put_contents($filename,$str);
    ob_flush();//关闭内存缓存
    echo"这还没缓存";

    }

    显示页面代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <table width="100%" cellpadding="0px" cellspacing="0px" border="1px">
    <tr>
    <td>代号</td>
    <td>课程</td>
    <td>类型</td>
    <td>操作</td>


    </tr>
    <{foreach $shuzu as $v}>

    <tr>
    <td><{$v[0]}></td>
    <td><{$v[1]}></td>
    <td><{$v[2]}></td>
    <td><a href="xiugai.php?code=<{$v[0]}>">修改</a></td>


    </tr>
    <{/foreach}>
    </table>
    <div><{$fpage}></div>
    </body>
    </html>

    效果

    此时没有缓存文件

    走起来后:

    默认显示的是第一页数据,缓存路径已经有了缓存文件。

    30秒后:

    '这还没缓存"不在出现,说明页面加载的是缓存文件。

    依次点2,3,4,5页后

    30秒后

    页面加载的是缓存文件,缓存路径文件:

    缓存页面均存在,操作成功。

  • 相关阅读:
    FPGA实现USB2.0同步读数据传输且用chipscop抓取波形(3)
    FPGA实现对USB2.0的同步数据传输及USB2.0固件配置(2)
    通过MATLAB实现图像数据转换成.bin格式在USB2.0上传输(1)
    【转】ssh免密码登录的原理
    【转】ssh登录原理以及ssh免密码登陆
    Windows与VMware中的CentOS系统互通访问
    第十一章 条件逻辑
    第十章 再谈连接
    第九章 子查询
    第八章 分组和聚集
  • 原文地址:https://www.cnblogs.com/F4natasy/p/6517222.html
Copyright © 2011-2022 走看看