Reputation: 14713
I'm reviewing my method for retrieving appsettings values from my config files. Before I would store the value in a static variable in a global ConfigurationManager class to avoid multiple unnecessary disk reads to the web.config file. It appears that was unnecessary as the WebConfigurationManager class already does this. Is this indeed the case? If I issue the following command 10 times in a row, how many times would it actually access the web.config file?
myConfigValue = WebConfigurationManager.AppSettings["MyConfigValue"];
Upvotes: 2
Views: 955
Reputation: 12396
none. the web.config file is read once, on application start...
Upvotes: 3
Reputation: 415735
It would only go to disk one time, and even then it probably already did it at the first request for any page in the app.
It will have to do a lookup on your "MyConfigValue"
string each time, so there might be some room for improvement if you can put this somewhere that you only need to do that part once.
Either way, it's a micro-optimization.
Upvotes: 3