views:

378

answers:

3

I have custom configuration section within web.config file. I'm lingering between:

  1. Reading it into static class every time when I need any configuration value (because I guess that system already caches files when I open them (for instance when I run Word it takes longer the first time and much less on consecutive opens))
  2. Reading it into static class and caching it using Application.Cache with file dependency and using cached data - I suppose it would be a bit quicker this way, but is it worth the hassle.

What do you think about auto file (on open) caching...

+2  A: 

AFAIK, config files are already cached in memory as long when the System.Configuration.ConfigurationManager is used.

Just one reason why changing a web.config/app.config requires an app restart to pick up changes

Josh E
+2  A: 

Reading values from web.config is very, very fast. The ConfigurationManager is highly optimized for the purpose. So fast that there is almost no gain over storing the value in Session, Cache, etc. However, if you store a setting in web.config changing the value restarts the app but the old cached value would still be present if you used the Cache ... so don't. Simply read the value from web.config when you need it; on a standard laptop I'm able to read a web.config setting over 600,000 times a second without issue.

Nissan Fan
well not exactly. If the application gets restarted, cache values are also "discarded" when the app closes.
Robert Koritnik
+2  A: 

Write a custom configuration section and use ConfigurationManager.GetSection

.NET Takes care of caching this and invalidates whenever the web.config file is changed.

Ramesh