专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » 实用价值的构造函数:简单实用的php缓存Cache函数 »正文

实用价值的构造函数:简单实用的php缓存Cache函数

来源: 发布时间:星期一, 2009年1月12日 浏览:54次 评论:0
  /**

  * @介绍说明: 文件缓存Cache输出

  * @参数: $cachefile => cache文件(绝对路径)

  * @参数: $pertime => 缓存Cache输出间隔时间

  * @参数: $sql => sql语句

  * @参数: $templatefile => 模板文件名称(绝对路径)

  **/

function __cache($cachefile,$pertime,$sql,$templatefile) {
global $db;
(time - @filemtime($cachefile) >= $pertime) {
 $query = $db->query($sql);
 while($r=$db->fetch($query)) {
  $cachelist = $r;
 } 
  $templatefile.'.php';
 $cacheserialize = serialize($cachelist);
 file_put_contents($cachefile,$cacheserialize);
}{
 $cachelist = unserialize(file_get_contents($cachefile));
  $templatefile.'.php';
}
}


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: