增加配置文件的内存缓存机制#54
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
当前ConfigUtil.getConfig方法不是个纯方法,这导致每次调用该方法时,都会执行一遍读取文件和判空的逻辑,造成了相当大不必要的开销。
而实际上配置文件的修改频率通常很低,尤其是我看见项目代码中大量出现相隔几行内即出现getConfigUtil().getConfig()语句,在这期间几乎可以肯定配置文件不会发生更改,因此我认为不需要每次都强制从硬盘刷新。
本PR在ConfigUtil内添加了对Config的缓存,并提供了reloadConfig方法,仅在手动调用该方法时才强制从硬盘刷新,预期可以大大减小读取配置文件时产生的不必要的开销。