views:

114

answers:

2

I have the following line of code called very often:

var configValue = System.Configuration.ConfigurationManager.AppSettings["ConfigValueKey"]; 

Do I take a disk hit for ASP.Net to retrieve the item from the web.config, or is it smart enough to cache the value in memory and only refresh the cache when the web.config changes?

+6  A: 

It is smart enough to cache all the attributes.

Kangkan
+4  A: 

The configuration data is kept in memory. However, ASP.NET will watch for changes in web.config and recycle the application domain if the file is changed.

Among other things all the user sessions will be lost, that's why it is not a good thing to touch the web.config while the application is running.

Daniel Melo
Session data is only lost if you are using session in process. If you are using a session server or sql sessions you should not have this problem.
Matthew Whited
@Daniel: Just to add: The recycling of the application is not only triggered by change in the config file only. Any change in the existing file or deletion of a file in the application will also cause it. You can see some other scenarios here: http://www.geekays.net/post/ASPNET-webdomain-recycle-on-subfolder-changes.aspx
Kangkan