最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
简单实例php 缓存文件生成技术实例
时间:2022-07-02 09:25:56 编辑:袖梨 来源:一聚教程网
class Cache
{
protected $_cacheDir;
public function __construct()
{
$this->_cacheDir = "./cache";
}
public function setCacheDir($cacheDir)
{
if(empty($cacheDir)){
$this->_cacheDir = $this->_cacheDir;
}else{
$this->_cacheDir = $cacheDir;
}
}
public function getCache($name)
{
$file_path = $this->_cacheDir.'/namma_cache-'.$name;
if(!file_exists($file_path))
{
return false;
}
$handle = @fopen($file_path,'rb');
$data = @fread($handle,filesize($file_path));
return $this->unformatData($data);
@flose($handle);
}
public function setCache($name,$data)
{
$file_path = $this->_cacheDir.'/namma_cache-'.$name;
$data = $this->formatData($data);
$fp = fopen($file_path, 'w');
fwrite($fp,$data);
fclose($fp);
return $file_path;
}
public function formatData($data)
{
return serialize($data);
}
public function unformatData($data)
{
return unserialize($data);
}
}
相关文章
- 《明日方舟终末地》陈千语怎么样-陈千语值得培养吗 07-04
- 《明日方舟终末地》余烬怎样配队-余烬阵容搭配推荐 07-04
- 《明日方舟终末地》骏卫怎么样-骏卫值得培养吗 07-04
- 《明日方舟终末地》莱万汀怎样配队-莱万汀强力配队推荐 07-04
- 《明日方舟终末地》原木怎样获得-原木获得方法 07-04
- 《长生天机降世》太虚境十天智遗迹幻境通关攻略-详细打法解析 07-04