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 开发者_如何学Goaccessing 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.
精彩评论