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

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

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

  • 相关阅读:
    oc-多态
    swifit OC 混合开发注意
    KVC的底层实现原理
    如何解除循环引用
    Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" 的问题原因及解决方案
    什么是上下文(Context)???
    "this class is not key value coding-compliant for the key ..."问题的解决
    svn: Can't connect to host
    SpringMVC @SessionAttributes 使用详解以及源码分析
    spring学习之@ModelAttribute运用详解
  • 原文地址:https://www.cnblogs.com/F4natasy/p/6517222.html
Copyright © 2011-2022 走看看