php操作缓存
生成
获取
删除
立即学习“PHP免费学习笔记(深入)”;
1 class file{ 2 private $_dir; 3 const EXT='.txt'; 4 public function __consruct(){ 5 $this->_dir dirname(__FILE___).'files/'; 6 } 7 public function cacheData($key,value='',$path=''){ 8 $filename = $this->_dir.$path.$key.self::EXT; 9 if($value!==''){//将value写入缓存 //删除缓存 if(is_null($value)){ return @unlike($filename) }10 $dir=dirname($filename);11 if(!is_dir($dir)){12 mkdir($dir,0777);13 }14 return file_put_contents($filename,jsonencode($value));15 } if(!is_file($filename)){ return FALSE; }else{ return json_decode(file_get_content($filename),true); }16 }24 25 } 26 27 28 //生成缓存29 $file= new firl();30 if($file->cacheData('index_mk_cache',$data)){31 32 echo "success";33 }else(34 echo "false";35 )36 //获取缓存$file= new firl(); if($file->cacheData('index_mk_cache')){ var_dump($file->cahceData('index_mk_cache'));exit; echo "success"; }else( echo "false"; )//删除缓存37
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号