Skip to content

Commit

Permalink
Merge pull request #42 from xianghuawe/master
Browse files Browse the repository at this point in the history
modify: module 支持不重启刷新 ,model支持强制刷新字段缓存
  • Loading branch information
weijer committed Apr 6, 2022
2 parents 17bf7ae + 319a5c2 commit b5e3ba2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/think/Model.php
Expand Up @@ -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;
Expand Down
40 changes: 36 additions & 4 deletions src/think/module/Module.php
Expand Up @@ -32,16 +32,29 @@ 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
*/
public static function init()
{
if (empty(self::$moduleDictData)) {
self::getModuleData();
self::generateModuleFieldCache(self::$moduleDictData['module_index_by_id']);
self::generateCustomHorizontalFieldsCache();
self::generateModuleData();
}
}

Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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;
}
}

0 comments on commit b5e3ba2

Please sign in to comment.