1

I have the following situation (.NET, C#):

My web service needs authentication data, which is stored in a database. The authentication is used for large volume POSTs done to the web service with transactional data. However, it is too heavy for to query the database every time there is a POST, because we are talking many transactions per second. I therefore want to keep the variables for authentication in Cache - which I can do via AppSettings. How do I load these variables into AppSettings when the web services is first started, without some manual process I need to remember to do?

Thanks, Anders

Anders
  • 894
  • 2
  • 10
  • 25
  • are you trying to cache your db connection object? – Ray Cheng May 30 '12 at 23:32
  • No; we have de-centralized systems on different continents that post call transaction data to the service, and it is the authentication data for these system, - and that is a list of IP addresses. – Anders May 30 '12 at 23:40
  • AppSetting is the part of web.config which is loaded when the application starts. So if you will add anything to AppSettings in web.config, after the application start, it will not have any impact unless you restart the application which will load web.config. SO I am not sure why do want to use AppSetting? AppSetting is good for default settings in web.config, not for dynamic data which is added at run time. Am i missing something here? – AvkashChauhan May 31 '12 at 00:45
  • Try using System.Web.Caching.Cache instead of App settings. – gk. May 31 '12 at 01:32

1 Answers1

0

It's not so easy to save information to web.config or app.config into AppSettings. Truly speaking, for me it's look dangerous when service tries to modify web.config, because a tiny error could cause all service to go down.

Anyway, when you need it, here is link for MSDN article, use ConfigurationManager class. And this article has a full example how to do it:

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

But I suggest you another approach. Use caching either simple System.Runtime.Caching.MemoryCache (or System.Web.Caching.Cache as in one of comments said) or more advanced and scalable scenario using AppFabric caching (for exampe have found link on stackoverflow for you)

Community
  • 1
  • 1
Regfor
  • 8,515
  • 1
  • 38
  • 51