From 856067b264fd6b9619cca1d4ab3f3c9a2bbc648e Mon Sep 17 00:00:00 2001 From: del xiong Date: Fri, 6 Aug 2021 22:21:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAMyFileConfig=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=86=85=E5=AD=98=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/common.php b/app/common.php index 6f93d0a44..c89b6dac6 100755 --- a/app/common.php +++ b/app/common.php @@ -334,6 +334,7 @@ function GetUrlHost($url) */ function MyFileConfig($key, $value = '', $default = null, $mandatory = false) { + static $fileConfigCache = []; // 目录不存在则创建 $config_dir = ROOT.'runtime'.DS.'data'.DS.'config_data'.DS; \base\FileUtil::CreateDir($config_dir); @@ -349,6 +350,10 @@ function MyFileConfig($key, $value = '', $default = null, $mandatory = false) // 读内容 if($value === '') { + $value = $fileConfigCache[$file] ?? ''; + if ($value) { + return $value; + } $value = file_exists($file) ? unserialize(file_get_contents($file)) : $default; if($mandatory === true) { @@ -357,10 +362,11 @@ function MyFileConfig($key, $value = '', $default = null, $mandatory = false) $value = $default; } } + $fileConfigCache[$file] = $value; return $value; - // 写内容 } else { + $fileConfigCache[$file] = $value; // 目录是否有可写权限 if(!is_writable($config_dir)) {