当前位置:首页 > 网络编程 > WEB编程 > PHP > 简单实用的缓存函数

简单实用的缓存函数

点击次数:31 次 发布日期:2008-11-22 11:51:39 作者:源代码网
源代码网推荐

/**
 * @说明: 文件缓存输出
 * @参数: $cachefile => cache文件(绝对路径)
 * @参数: $pertime => 缓存输出的间隔时间
 * @参数: $sql => sql语句
 * @参数: $templatefile => 模板文件名称(绝对路径)
**/
function __cache($cachefile,$pertime,$sql,$templatefile) {
 global $db;
 if(time() - @filemtime($cachefile) >= $pertime) {
  $query = $db->query($sql);
  while($r=$db->fetch($query)) {
   $cachelist[] = $r;
  } 
  include $templatefile.".php";
  $cacheserialize = serialize($cachelist);
  file_put_contents($cachefile,$cacheserialize);
 }else{
  $cachelist = unserialize(file_get_contents($cachefile));
  include $templatefile.".php";
 }
}

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华