Commit 59a94a9c authored by Euan游根明's avatar Euan游根明

perf: 写入文件

parent e7ed2c1c
...@@ -211,6 +211,9 @@ class Nacos ...@@ -211,6 +211,9 @@ class Nacos
*/ */
public static function NacosGet($key){ public static function NacosGet($key){
$path =self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).self::$configs['APP_ENV']; $path =self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).self::$configs['APP_ENV'];
if (!file_exists($path)) {
return '';
}
$data = json_decode( $data = json_decode(
file_get_contents($path), file_get_contents($path),
true, true,
...@@ -225,19 +228,24 @@ class Nacos ...@@ -225,19 +228,24 @@ class Nacos
* 写入文件 * 写入文件
* @param $key * @param $key
* @param $value * @param $value
* @return void * @return false|int
*/ */
public static function NacosPut($key,$value){ public static function NacosPut($key,$value){
$path = self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).self::$configs['APP_ENV']; $path = self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).self::$configs['APP_ENV'];
if (!file_exists($path)) {
$data[$key] = $value;
return file_put_contents($path, json_encode($data));
}
$data = json_decode( $data = json_decode(
file_get_contents($path), file_get_contents($path),
true, true,
); );
$data[$key] = $value; $data[$key] = $value;
file_put_contents( return file_put_contents(
$path, $path,
json_encode($data), json_encode($data),
); );
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment