您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php开发app接口之静态缓存

2024/2/18 12:48:25发布22次查看
(1) 静态 缓存 这里技术的本质是我们将我们所需要的一些数据临时存在服务器的一些文件中。 ?php class file { private $_dir ; const ext= 'php' ; public function __construct () { $this -_dir=dirname( __file__ ). '/files/' ; } public function cache
(1)静态缓存
这里技术的本质是我们将我们所需要的一些数据临时存在服务器的一些文件中。
_dir=dirname(__file__).'/files/'; } public function cachedate($key,$value='',$path='') { $filename=$this->_dir.$path.$key.self::ext; //将value值写入缓存 if($value!=='') { //如果value值为null if(is_null($value)) { return unlink($filename); } $dir=dirname($filename); if(!is_dir($dir)) { mkdir($dir,0777); } return file_put_contents($filename,json_encode($value)); } if(!is_file($filename)) { return false; } else { return json_decode(file_get_contents($filename),true); } }}
这里封装了一个类,下面是测试代码
1, 'name'=>'singwa', 'type'=>array(4,5,6), 'test'=>array(1,45,67=>array(123,'tsysa')),);$file=new file();//增加缓存的方式 这样会将指定的数据放入指定文件夹中if($file->cachedate('index_mk_cache'),$data){ var_dump($file->cachedate('index_mk_cache')); echo success;}else { echo error;}//取出缓存的方式if($file->cachedate('index_mk_cache')){ var_dump($file->cachedate('index_mk_cache')); echo success;}else { echo error;}//删除缓存的方式if($file->cachedate('index_mk_cache'),$value=null){ var_dump($file->cachedate('index_mk_cache')); echo success;}else { echo error;}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product