From 319a5c2e263c97d1a5ef650d5542fd1297ecb45c Mon Sep 17 00:00:00 2001 From: coder_wen Date: Wed, 6 Apr 2022 14:31:47 +0800 Subject: [PATCH] =?UTF-8?q?modify:=20module=20=E6=94=AF=E6=8C=81=E4=B8=8D?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E5=88=B7=E6=96=B0=20,model=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E5=88=B7=E6=96=B0=E5=AD=97=E6=AE=B5=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/think/Model.php | 5 +++-- src/think/module/Module.php | 40 +++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/think/Model.php b/src/think/Model.php index bdbfc31..1de3a63 100644 --- a/src/think/Model.php +++ b/src/think/Model.php @@ -318,15 +318,16 @@ protected function _checkTableInfo() /** * 获取字段信息并缓存 * @param string $tableName + * @param bool $must 是否必须刷新 * @return mixed */ - public function flush($tableName = '') + public function flush($tableName = '', $must = false) { if (empty($tableName)) { $tableName = $this->getTableName(); } - if (C('DB_FIELDS_CACHE')) { + if ($must === false && C('DB_FIELDS_CACHE')) { $fieldsCache = S('fields_' . strtolower($tableName)); if (!empty($fieldsCache)) { return $fieldsCache; diff --git a/src/think/module/Module.php b/src/think/module/Module.php index c316170..e83b25e 100644 --- a/src/think/module/Module.php +++ b/src/think/module/Module.php @@ -32,6 +32,21 @@ class Module // 包含租户id的模块列表数据 public static $includeTenantIdModules = []; + // 刷新缓存锁 + protected static $refreshLock = false; + + /** + * 初始化数据 + * @return void + * @throws \Exception + */ + private static function generateModuleData() + { + self::getModuleData(); + self::generateModuleFieldCache(self::$moduleDictData['module_index_by_id']); + self::generateCustomHorizontalFieldsCache(); + } + /** * 模块初始化 * @throws \Exception @@ -39,9 +54,7 @@ class Module public static function init() { if (empty(self::$moduleDictData)) { - self::getModuleData(); - self::generateModuleFieldCache(self::$moduleDictData['module_index_by_id']); - self::generateCustomHorizontalFieldsCache(); + self::generateModuleData(); } } @@ -174,7 +187,7 @@ public static function checkSchema() // 清除数据表字段缓存 Cache::init(config('redis')); - foreach ($tables as $tableName){ + foreach ($tables as $tableName) { S('fields_' . strtolower($tableName), null); } Cache::destroy(config('redis')); @@ -231,4 +244,23 @@ public static function setTenantIdModules($moduleCOde = '') self::$includeTenantIdModules[] = $moduleCOde; } } + + /** + * 刷新模块配置 + * @return bool + * @throws \Exception + */ + public static function refreshModuleConfig() + { + if (self::$refreshLock) { + return false; + } + self::$refreshLock = true; + try { + self::generateModuleData(); + } finally { + self::$refreshLock = false; + } + return true; + } }