阅读 app.config 很贵吗? [英] Is reading app.config expensive?

查看:25
本文介绍了阅读 app.config 很贵吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

毫无疑问,我还没有遇到任何读取速度瓶颈.我想知道;如果经常阅读 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.

这里有一些阅读:

关于您访问​​另一个应用程序的配置文件的要求:

Regarding to your requirement to access another application's config file:

MSDN:这些方法(注意:对于客户端应用程序:ConfigurationManager.GetSection) 提供对缓存当前应用程序的配置值,它比 Configuration 类具有更好的性能."

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."

换句话说:是的,当它不是您自己应用的配置文件时,您应该缓存它.

这篇关于阅读 app.config 很贵吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆