21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
class Data_cache
{
//缓存文件存放的地址
private $file = "/usr/www/program/cache/";
//文件的名称
private $filename = "filename";
//需要写入缓存文件的数据
private $data = "";
public function __construct($filename,$data)
{
$this->filename = $filename;
$this->data = $data;
if($this->judge_cache_file_exists())
{
$this->put_data_to_file();
}
}
//写入缓存文件
public function put_data_to_file($data)
{
if(isset($data))
{
$dir = $file.md5($filename).".php";
file_put_contents($dir,$this->data);
}else{
return FALSE;
}
}
//判断缓存文件是否存在
public function judge_cache_file_exists()
{
return file_get_contents($file.md5($filename).".php",$this->data);
}
}
?>
$data = "这是需要缓存的数据";
$filename = "filename";
$cache = new Data_cache($filename,$data);