最新下载
热门教程
- 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);
}
}
相关文章
- 阿里云企业邮箱官网入口-阿里云企业邮箱最新防走失直达通道 03-21
- 王者荣耀P5P玩法全解析 王者荣耀竞技对战模式深度指南 03-21
- venera安卓版下载入口-venera安卓最新版安装包下载官网 03-21
- 世界之光手游上线时间确认了吗 世界之光手游全平台公测日期汇总 03-21
- 云顶之弈暗夜猎手薇恩出装、技能、羁绊介绍 03-21
- keep奖牌怎样快速获取-keep奖牌必须付费吗 03-21