diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index a072f41f..6b1abd19 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -63,10 +63,11 @@ class File extends Driver /** * 取得变量的存储文件名 * @access protected - * @param string $name 缓存变量名 + * @param string $name 缓存变量名 + * @param bool $auto 是否自动创建目录 * @return string */ - protected function getCacheKey($name) + protected function getCacheKey($name, $auto = false) { $name = md5($name); if ($this->options['cache_subdir']) { @@ -78,7 +79,8 @@ class File extends Driver } $filename = $this->options['path'] . $name . '.php'; $dir = dirname($filename); - if (!is_dir($dir)) { + + if ($auto && !is_dir($dir)) { mkdir($dir, 0755, true); } return $filename; @@ -144,7 +146,7 @@ class File extends Driver if ($expire instanceof \DateTime) { $expire = $expire->getTimestamp() - time(); } - $filename = $this->getCacheKey($name); + $filename = $this->getCacheKey($name, true); if ($this->tag && !is_file($filename)) { $first = true; }