最新下载
热门教程
- 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);
}
}
相关文章
- 山海进化录不同商店购买推荐 12-16
- 学信网官方登录入口-安全快捷的账号登录指引 12-16
- 青灯照鳞莲生与青玲儿获取攻略分享 12-16
- 豆包网页版官网入口在哪 豆包官网网址是什么 12-16
- 植物大战僵尸杂交版小鬼投石车僵尸怎么攻击 植物大战僵尸杂交版小鬼投石车僵尸核心玩法机制 12-16
- 小红书网页版极速登录入口-小红书网页版扫码免密一键直达 12-16