在读的app.config贵吗? [英] Is reading app.config expensive?
问题描述
没有问题,我还没有任何读取速度的瓶颈被击中。我打听才知道;如果经常阅读的app.config是一个糟糕的节目选择。我知道数据库的操作越来越昂贵的。
No question I am yet to be hit by any read speed bottleneck. I am asking to know; if reading app.config frequently is a bad programming choice. I have known of database operations getting expensive.
在我来说,我不念我自己的应用程序的app.config,但另一个项目的像这样的:
private string GetAppConfigValue(string key)
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = GetConfigFilePath();
Configuration appConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
return appConfig.AppSettings.Settings[key].Value;
}
场景:我有一个管理器类(只有其中一类),我必须从物理路径指定的配置文件,阅读几个值(3〜4),但很多时候。需要我很少有成员变量存储从app.config文件中的值?什么是最好的办法。谢谢你。
Scenario: I have a manager class (and only one such class) where I have to read few values (3 to 4) from a config file specified by a physical path, but many times. Need I have few member variables to store the values from app.config file? What would be the best approach. Thanks.
推荐答案
我敢肯定,所有的配置文件(web.config中或app.config)中是默认缓存,所以你并不需要创建一个包含所有值的静态类或怕这些文件都将被永久访问
I'm sure that all configuration files(web.config or app.config) are cached by default, so you don't need to create a static class that holds all values or be afraid that the files are accessed permanently.
下面是一些阅读:
- Web.Config is Cached
- ConfigurationManager.RefreshSection Method
- Application Configuration Files Explained
- ASP.NET Configuration Overview
关于您的要求访问其他应用程序的配置文件:
Regarding to your requirement to access another application's config file:
MSDN :这些方法(注:客户端应用程序: ConfigurationManager.GetSection 的)提供了访问缓存当前应用程序,它具有比配置类更好的性能配置值。
MSDN: "These methods(note: for client applications: ConfigurationManager.GetSection) provide access to the cached configuration values for the current application, which has better performance than the Configuration class."
在换句话说:是,你应该缓存它时,它不是自己的应用程序的配置文件
In other words: Yes, you should cache it when it's not your own app's config file.
这篇关于在读的app.config贵吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!