return (file_exists($file) and _CacheEnable_ and !$ischange);
}
//读取Cache
function read()
{
//返回当前页的Cache
$file=_CachePath_."/".$this->cachefile;
//读取Cache文件的内容
if (_CacheEnable_) return readfile($file);
else return false;
}
//生成Cache
function write($output)
{
//返回当前页的Cache
$file=_CachePath_."/".$this->cachefile;
//如果Cache功能开启
if (_CacheEnable_)
{
//把输出的内容写入Cache文件
$fp=@fopen($file,'w');
if (!@fputs($fp,$output)) {echo "模板Cache写入失败";exit;}
@fclose($fp);
//如果设置了缓存更新间隔时间 _ReCacheTime_
if (_ReCacheTime_+0>0)
{
//更新当前页Cache的最后更新时间
$file=_CachePath_."/".$this->cachefilevar;
$fp=@fopen($file,'w');
if (!@fwrite($fp,time())) {echo "Cache目录无法写入";exit;}
@fclose($fp);
}
}
}
}
?>
类的使用:
[php] view plaincopy
define("_CachePath_","./cache/");
define("_CacheEnable_","1");
define("_ReCacheTime_","43200");
include('cache.php');
$cache=new cache();
if ($cache->check())
{
$template=$cache->read();
}
else
{
ob_start();
ob_implicit_flush(0);
?>
页面内容。。。。
$template = ob_get_contents();
$cache->write($template);
}
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn