示例#1
0
 /**
  * 缓存获取与设置结束,存入文件或者内存
  * @param null $cacheTime
  * @return bool
  */
 public function cacheSave($cacheTime = null)
 {
     if (isset($cacheTime) && !empty($cacheTime)) {
         $this->setCacheTime($cacheTime);
     }
     if ($this->ifGetByEcho) {
         // 获取输出缓冲数据
         $this->cacheContent = ob_get_contents();
         ob_end_flush();
     }
     // 更新内存中的缓存信息
     $this->cacheInfo[$this->cacheDigest]['expiredTime'] = $this->cacheTime;
     $this->cacheInfo[$this->cacheDigest]['expiredDateTime'] = date("Y-m-d H:i:s", $this->cacheTime);
     $ifSave = false;
     // 缓存文件地址
     $cacheContentFile = new FileLoader(PathGeneration::getFolder("{$this->cachePath}{$this->cacheId}") . "{$this->cacheDigest}.tmp", array("mode" => "write"));
     $cacheInfoFile = new FileLoader("{$this->cachePath}{$this->cacheId}_info.tmp", array("mode" => "write"));
     if ($cacheInfoFile->isWritable()) {
         if ($cacheContentFile->isWritable()) {
             $cacheInfoFile->write(json_encode($this->cacheInfo));
             $cacheContentFile->write($this->cacheContent);
             $cacheContentFile->close();
             $ifSave = true;
         }
         $cacheInfoFile->close();
     }
     return $ifSave;
 }