Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationManager.AppSettings Caching

We know that IIS caches ConfigurationManager.AppSettings so it reads the disk only once until the web.config is changed. This is done for performance purposes.

Someone at:

http://forums.asp.net/p/1080926/1598469.aspx#1598469

stated that .NET Framework doesn't do the same for app.config, but it reads from the disk for every request. But I find it hard to believe, 'cause it would be slower. Please tell me that he is wrong or I'll have to fix every Console/Windows Forms/Windows Services I wrote.

Update I regret that I misinterpreted what people said in the linked forum above.

like image 759
Jader Dias Avatar asked Dec 23 '08 16:12

Jader Dias


People also ask

Are appSettings cached?

AppSettings is cached. You can improve performance by further caching to limit namevaluecollection lookups.

What is ConfigurationManager appSettings?

it is a .net builtin mechanism to define some settings before the application starts, without recompiling. see msdn configurationmanager.

Does ConfigurationManager work in .NET core?

ConfigurationManager was added to support ASP.NET Core's new WebApplication model, used for simplifying the ASP.NET Core startup code.

What is the use of ConfigurationManager in C#?

The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class, which is deprecated. For web applications, use the WebConfigurationManager class.


1 Answers

A quick test seems to show that these settings are only loaded at application startup.

//edit the config file now. Console.ReadLine();  Console.WriteLine(ConfigurationManager.AppSettings["ApplicationName"].ToString()); Console.WriteLine("Press enter to redisplay");  //edit the config file again now. Console.ReadLine(); Console.WriteLine(ConfigurationManager.AppSettings["ApplicationName"].ToString()); Console.ReadLine(); 

You'll see that all outputs remain the same.

like image 185
ZombieSheep Avatar answered Oct 11 '22 17:10

ZombieSheep