阅读 app.config 很贵吗?

编程入门 行业动态 更新时间:2024-10-10 06:20:28
本文介绍了阅读 app.config 很贵吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

毫无疑问,我还没有遇到任何读取速度瓶颈.我想知道;如果经常阅读 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 已缓存ConfigurationManager.RefreshSection 方法 应用程序配置文件说明ASP.NET 配置概述

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

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 22:58:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/923606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:app   config   很贵吗

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!