zoukankan      html  css  js  c++  java
  • 05 使用静态缓存

    <?php 
    
    
    class File{
    
        public  $_dir;
    
        const EXT='.txt';
    
        public function __construct(){
    
            $this->_dir=dirname(__FILE__).'/file/';
        }
    
    
    
        public function cacheData($key,$value='',$path=''){
    
             $filename=$this->_dir.$path.$key.self::EXT;
    
             #删除
            if(is_null($value)){
    
                 return unlink($filename);
            }
    
       
            #创建
            if($value!=""){
    
                 $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);
             }
    
    
    
        }
    }
    
       $data=array(
        'id'=>1,
        'name'=>'hgj123',
       );
    
      $file=new File();
      //var_dump($file->cacheData('cachae'));
      if($file->cacheData('cachae',null)){
          echo "OK";
    
      }else{
        echo "NO";
      }
  • 相关阅读:
    学习C++的第一天
    2016.12.28
    无主之地
    一种排序
    街区最短问题
    配对类问题
    蛇形填数
    c#unity
    贪心
    台阶
  • 原文地址:https://www.cnblogs.com/hgj123/p/4354155.html
Copyright © 2011-2022 走看看