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秒后

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

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

  • 相关阅读:
    记一次GreenPlum性能调优
    PostgreSQL时间格式及相关函数实践
    OGG到OGGAdapter配置详情-从Oracle直接抽取成csv文件
    使yum保留下载的rpm包
    源码编译tmux
    抠图
    ps磨皮的方法
    谷歌学术网站镜像
    element菜单默认展开和选中
    git仓库如果是私密的,每台电脑上导下来都需要进行ssh授权,所以一个项目不知一个ssh权限
  • 原文地址:https://www.cnblogs.com/F4natasy/p/6517222.html
Copyright © 2011-2022 走看看