Skip to content

增加配置文件的内存缓存机制#54

Merged
linyuchen merged 2 commits into
LLOneBot:v3.4.0from
disymayufei:main
Feb 19, 2024
Merged

增加配置文件的内存缓存机制#54
linyuchen merged 2 commits into
LLOneBot:v3.4.0from
disymayufei:main

Conversation

@disymayufei
Copy link
Copy Markdown
Contributor

当前ConfigUtil.getConfig方法不是个纯方法,这导致每次调用该方法时,都会执行一遍读取文件和判空的逻辑,造成了相当大不必要的开销。

而实际上配置文件的修改频率通常很低,尤其是我看见项目代码中大量出现相隔几行内即出现getConfigUtil().getConfig()语句,在这期间几乎可以肯定配置文件不会发生更改,因此我认为不需要每次都强制从硬盘刷新。

本PR在ConfigUtil内添加了对Config的缓存,并提供了reloadConfig方法,仅在手动调用该方法时才强制从硬盘刷新,预期可以大大减小读取配置文件时产生的不必要的开销。

@linyuchen linyuchen merged commit 4e4ccf4 into LLOneBot:v3.4.0 Feb 19, 2024
linyuchen added a commit that referenced this pull request Nov 29, 2024
增加配置文件的内存缓存机制
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants