优化File缓存自动生成空目录的问题

This commit is contained in:
thinkphp
2018-01-22 17:16:21 +08:00
parent 430607bc61
commit af2d18f923

View File

@@ -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;
}