* [refac] refactor method to enable cache by apcu after installed.

This commit is contained in:
liugang
2024-11-20 15:42:49 +08:00
committed by 朱金勇
parent 4d07bea835
commit adcf3b0caa
3 changed files with 15 additions and 22 deletions
+1 -11
View File
@@ -381,17 +381,7 @@ class install extends control
$this->install->importBIData();
$this->install->enableDaoCache();
/**
* 安装完成后清除缓存。
* 通过 dao 的 exec 方法更新数据库会自动更新缓存。
* 通过 dbh 执行 sql 语句的方式更新数据库不会自动更新缓存,应该在清除缓存之前执行,否则可能导致缓存命中但数据已过期。
* Clear the cache after the installation is complete.
* Update the database through the exec method of dao will automatically update the cache.
* Update the database by executing sql statements through dbh will not automatically update the cache, should be executed before clearing the cache, otherwise it may cause cache hits but the data has expired.
*/
$this->dao->clearCache();
$this->install->enableCache();
$skipApp = (string)getenv('ZT_SKIP_DEVOPS_INIT');
$link = ($this->config->inQuickon && (!$skipApp || $skipApp == 'false')) ? inlink('app') : inlink('step6');
+13 -10
View File
@@ -423,24 +423,27 @@ class installModel extends model
}
/**
* 开启 dao 缓存。
* Enable dao cache.
* 开启缓存。
* Enable cache.
*
* @access public
* @return bool
*/
public function enableDaoCache(): bool
public function enableCache(): bool
{
if(!helper::isAPCuEnabled()) return false;
$cache = new stdclass();
$cache->owner = 'system';
$cache->module = 'common';
$cache->section = 'global';
$cache->key = 'cache';
$cache->value = '{"dao":{"enable":"1"}}';
$this->dao->replace(TABLE_CONFIG)->data($cache)->exec();
$cache->status = true;
$cache->driver = 'apcu';
$cache->scope = 'shared';
$cache->namespace = $this->config->db->name;
return !dao::isError();
$this->loadModel('setting')->setItems('system.common.cache', $cache);
if(dao::isError()) return false;
$this->mao->clearCache();
return true;
}
}
+1 -1
View File
@@ -9214,7 +9214,7 @@ class upgradeModel extends model
*/
public function openCacheByAPCu(): bool
{
return $this->loadModel('install')->enableDaoCache();
return $this->loadModel('install')->enableCache();
}
/**