$cacheTime = sprintf('%011d', $cacheTime); return file_put_contents($this->fileName, $cacheTime . json_encode($value)); } else { if ($this->fileName) { //删除缓存文件 unlink($this->fileName); } } } catch (Exception $e) { throw $e; } } //获取换缓存的方法、 public function getCache($key) { $this->fileName = $this->dir . $key . self::EXT; $contents = file_get_contents($this->fileName); $time = substr($contents, 0, 11); $value = substr($contents, 11); if ($time + filemtime($this->fileName) < time()) { echo '缓存已经过期'; unlink($this->fileName); return false; } return $value; } } $cache = new FileCache(); //$cache->setCache('as','ajksdfhka',10); echo $cache->getCache('as');