一、TP6.0生成缓存文件
1.先设置好缓存路径:config/cache.php

2.生成与读取缓存
//生成
$rs = Cache::store('xxx')->set('name','111');
//读取
Cache::store('xxx')->get('name');
生成的缓存文件就在这里:runtime\xxx
官网文件:https://www.kancloud.cn/manual/thinkphp6_0/1037634
二、tp5.1 生成缓存文件
官方文档:https://www.kancloud.cn/manual/thinkphp5_1/354116
要引入:use think\facade\Cache;
助手快速缓存
创建缓存:$rs = cache('comment_confing',$data);
读取缓存:var_dump(cache('comment_confing'));
一、储存简单数据
1.1生成 缓存文件
生成文件的路径:\runtime\pay\
//写入缓存
$rs = Cache::connect(['path'=>env('runtime_path').'pay/'])->set('payconfing',$arr);
//读缓存
$rs = Cache::connect(['path'=>env('runtime_path').'pay/'])->get('payconfing');
或
    public function makepaycofing(){
        
            //$action=input('action');
            
            $path = env('runtime_path').'pay/';
            $option['path'] = $path;//缓存路径
            $file_name="payconfing";//缓存文件名称
            $arr='11';
            $rs = Cache::connect($option)->set($file_name,$arr);
                
            if($rs){
                $data['code']=1;
                $data['msg']='成功';
            }else{
                $data['code']=0;
                $data['msg']='失败';
            }
            return $data;
        
    }1.2、读取缓存数据
          $path = env('runtime_path').'pay/';
          $file_name="payconfing";//缓存文件名称
          $data1 = Cache::connect(['path'=>$path])->get($file_name);
          //dump(Cache::connect($option)->get($file_name)); exit;
          
          dump( $data1);例子:读缓存时找不到然后再新生成缓存再读
        $path = env('runtime_path').'index/';
        $file_name="product";//缓存文件名称
        $pdata = Cache::connect(['path'=>$path])->get($file_name);
      $productData = json_decode($pdata,true);
//      dump($productData);die;
      if($productData['code']!=200 || empty($productData)){
        $crsp=model('admin/ProductModel')->make_product_cache();
        $code=$crsp['code'];
        $msg=$crsp['msg'];
        if($code==200){//生成成功
          $pdata = Cache::connect(['path'=>$path])->get($file_name);
          $productData = json_decode($pdata,true);
        }
      }
//      dump($productData);
      return ['code'=>$code,'msg'=>$msg,'data'=>$productData?$productData:[]];
二、储存数组
    public function makepaycofing(){
        
            //$action=input('action');
            
            $path = env('runtime_path').'pay/';
            $option['path'] = $path;//缓存路径
            $file_name="payconfing";//缓存文件名称
            $arr['wx']['code']=1;
            $arr['wx']['msg']='成功';
            $arr['ap']['code']=2;
            $arr['ap']['msg']='成功2';
            $rs = Cache::connect(['path'=>$path])->set($file_name,$arr);
                
            if($rs){
                $data['code']=1;
                $data['msg']='成功';
            }else{
                $data['code']=0;
                $data['msg']='失败';
            }
            return $data;
        
    }          $path = env('runtime_path').'pay/';
          $file_name="payconfing";//缓存文件名称
          $data1 = Cache::connect(['path'=>$path])->get($file_name);
          dump( $data1['wx']);array(2) {
  ["code"] => int(1)
  ["msg"] => string(6) "成功"
}只取wx数组的数据








