我有點不太清楚 public function cachedata($key,$value='',$path='') 里面有三個形參 下邊調(diào)用的時候為什么只有兩個實參 一個文件名 ,一個路徑
public function cachedata($key,$value='',$path=''){
? ? ? ?$filename=$this->_dir.$path.$key.self::EXT; ? ?//文件名
? ? ? ?// ?api/files/ $path.文件名.后綴
? ? ? ?// ? api/files/$path.index_m_cache.txt
//判斷 如過這個值(緩存數(shù)據(jù))不為空就寫如緩存
? ? ? ?if($value!==''){//將value的值寫入緩存
? ? ? ? ? ?//刪除緩存
? ? ? ? ? ?if(is_null($value)){
? ? ? ? ? ? ? return ?@unlink($filename);
? ? ? ? ? ?}
? ? ? ? ? ?$dir=dirname($filename); ? //api/files/
//判斷這個目錄是否存在 ? 不存在就創(chuàng)建這個目錄
? ? ? ? ? ?if(!is_dir($dir)){
? ? ? ? ? ? ? ?mkdir($dir,0777);
? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//api/files/index_mk/cache.txt
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //路徑(目錄) ? ?值
? ? ? ?return ? ?file_put_contents($filename,json_encode($value));
? ? ? ?}
//獲取緩存
//判斷文件是否存在 ? 不存 在就返回false ? 存在就獲取文件的值
? ? ? ?if(!is_file($filename)){
? ? ? ? ? ? ? ?return false;
? ? ? ?}else{
? ? ? ? ? ?return json_decode(file_Get_contents($filename),true);
? ? ? ?}
我有點不太清楚 ? ??public function cachedata($key,$value='',$path='') ?里面有三個形參 ? 下邊調(diào)用的時候為什么只有兩個實參 ?一個文件名 ,一個路徑
2017-12-20
public function cachedata($key,$value='',$path='')? ? 里面的 第二個參數(shù)與第三個參數(shù)有默認(rèn)值為空