最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php文件缓存技术实现代码
时间:2022-06-24 18:25:06 编辑:袖梨 来源:一聚教程网
class pagecache {
/**
* @var string $file 缓存文件地址
* @access public
*/
public $file;
/**
* @var int $cachetime 缓存时间
* @access public
*/
public $cachetime = 3600;
/**
* 构造函数
* @param string $file 缓存文件地址
* @param int $cachetime 缓存时间
*/
function __construct($file, $cachetime = 3600) {
$this->file = $file;
$this->cachetime = $cachetime;
}
/**
* 取缓存内容
* @param bool 是否直接输出,true直接转到缓存页,false返回缓存内容
* @return mixed
*/
public function get($output = true) {
if (is_file($this->file) && (time()-filemtime($this->file))<=$this->cachetime && !$_get['nocache']) {
if ($output) {
header('location:' . $this->file);
exit;
} else {
return file_get_contents($this->file);
}
} else {
return false;
}
}
/**
* 设置缓存内容
* @param $content 内容html字符串
*/
public function set($content) {
$fp = fopen($this->file, 'w');
fwrite($fp, $content);
fclose($fp);
}
}
相关文章
- 我的常州怎么查社保卡余额 我的常州查询医保卡余额方法 05-06
- 天刀共鸣技能搭配攻略(掌握共鸣技能,提升天刀战斗实力) 05-06
- 《Neverness To Everness》周年庆委托任务在哪里介绍 05-06
- 纳米ai怎么修改资料 纳米ai修改资料方法 05-06
- 月蚀技能攻略(掌握月蚀技能,成为真正的黑暗之王!) 05-06
- 纳米ai怎么静音 纳米ai静音方法 05-06