简体   繁体   中英

Application Variable Vs Web.Config Variable

Which is better from a performance perspective?

  • Accessing a Global Application Variable (Application["foo"])

versus

  • Accessing an AppSetting variable from the web.config

Does .NET Cache the AppSetting variables so that it is not accessing the web.config file with every use?

These two things are not comparable. appSettings , or any other configuration settings, are for configuration settings. Application variables are for quantities that might change during the course of the application, or are for things like tables of domain data values. These latter are things which you would not place into a configuration file, because they change rarely, and do not need to be configured.

appSettings and everything else in a config file, is cached. The file is only read once per AppDomain, in general. In fact, when you change your web.config, it causes an AppDomain restart, mainly so that the new configuration settings can be read in.

appSettings are apparently not cached

EDIT: Seems both appSettings and Application variables would be the same speed then. After the initial load of course.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM