views:

1509

answers:

4

I read somewhere in the Microsoft documentation that the content of the ASP.NET's web.config is cached. If that is true, where is it cached - in memory or on disk?

And a follow-up question: are there any performance considerations I have to make, if I have to access the web.config intensively?

+1  A: 

I think that the web.config is cached in memory (in object instances from System.Web.Configuration). Those are reloaded when the .config file is changed (and thus reloading your web app).

Hitting those objects is unlikely to give you a performance bottleneck. But if you have to do parsing etc, you might want to hold on the the parsed objects.

[Extra] I good practice (I think at least) is to create static properties in your global.asax.cs file for you appsettings. You can instantiate those properties in the application_start method and use them through out your web app. This prevents you from using hard-coded string (configuration keys) throughout your code.

Michiel Overeem
+1  A: 

It's cached in memory. Caching on disk doesn't make a lot of sense for something that's accessed often and is already in a format where you can turn it into an easily stored data structure. My advice would be to freely access it as it will be as fast as any scheme you come up with for storing it and probably faster.

Jon
+2  A: 

Its cached in memory, caching on disk doesn't make any sense, its already on disk.

First of all in ASP.NET you want to ensure you access configuration sections through the HttpContext object's GetSection method (this uses the cached copies managed by ASP.NET).

Performance of accessing config values is a function of the internal implementation of the Section object (the object returned by GetSection). A ConfigurationSection may simply act as wrapper for a DOM node which it may read on every request for a property. OTH it could internaly cache the value and watch for changes.

My advice would be keep your code simple and just access the values you need via GetSection rather than attempt to hold copies of them elsewhere but by all means maintain a reference to the object returned by GetSection for the duration of a request if you are going to fetch multiple values from it.

AnthonyWJones
On disk could be in a serialized way... okay, okay it's silly, I know. Didn't think as I wrote that... :-)
splattne