最新下载
热门教程
- 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);
}
}
相关文章
- 企查查企业查询-企查查企业信息查询 01-30
- 小说君有疾否免费阅读入口地址-原著小说君有疾否各人物结局揭晓 01-30
- 喵趣漫画官方网站入口:高清无删减漫画资源首发观看地址 01-30
- 163邮箱官网登录入口网页版-163邮箱官方快捷登录入口 01-30
- 哔咔漫画官网入口-哔咔官网镜像流畅不卡 01-30
- jk漫画最新版本下载入口-jk漫画安卓安装包一键下载直达 01-30