ConfigurationBuilder类用来返回存储区中当前配置设置。基于性能的考虑,当每一个配置节信息从存储区读取后,ConfigurationBuilder将缓存该配置信息。只要缓存信息与底层存储区数据保持一致,缓存信息将返回给应用程序。当Storage Provider检测到配置设置发生变化时,它将触发一个事件,表示该配置节发生了变化。当ConfigurationBuilder接受到该事件时,将从缓存中清除该配置节信息。这样,在应用程序下次尝试读取该节配置信息时,ConfigurationBuilder将从存储区直接读取新的配置信息。

当使用XML文件的Storage Provider时,从配置文件发生改变到检测到该改变大约存在1500毫秒的延迟。ConfigurationChangeFileWatcher对象每1500毫秒轮询XML配置文件的变化,这不是一个可配置的设置。不过,你可以通过修改ConfigurationChangeFileWatcher源代码来改变轮询的频率。

另外,Client端程序也可以通过调用ConfigurationManager.ClearSingletonCache方法来清除缓存。

Code Snippet如下所示:

private void btnClearCache_Click(object sender, System.EventArgs e)

{

// Removes all sections from the internal cache.

ConfigurationManager.ClearSingletonSectionCache();

txtConfigurationData.Text += "The cache of configuration data has been cleared." + Environment.NewLine;

}

相关文章:

  • 2021-08-31
  • 2021-12-07
  • 2021-07-09
  • 2021-09-24
  • 2021-09-26
  • 2022-01-08
  • 2021-04-16
猜你喜欢
  • 2021-05-15
  • 2021-05-29
  • 2021-08-03
  • 2021-11-24
  • 2021-12-11
  • 2022-01-22
相关资源
相似解决方案