最新下载
热门教程
- 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-01
- Hyperliquid 价格能否在 2025 年第三季度创新高 07-01
- 标普500指数上链!Centrifuge 和 S&P DJI 共同宣布「24/7交易」来了 07-01
- 金铲铲之战s14超频源计划纳亚菲利阵容攻略 07-01
- 燕云十六声金妙音石归鸿速刷攻略 07-01
- 崩坏星穹铁道3.2末日幻影打法技巧指南 07-01