I need to store a Dictionary in my asp .net application. This dictionary is basically a straight mapping of keys (strings) to values (strings). During the life of the Application the dictionary will not change and will contain about 10 elements.
I will be iterating over possibly thousands of rows returned from a stored procedure and obtaining corresponding values from this dictionary.
What would be the best approach to tackle this? Here are the 2 ideas I have on implementing it:
Or ...
I like option 2 since adding a new value in the future is just a matter of adding an entry in Web.Config without any code changes whatsoever but I'm concerned about performance since I will have to obtain a value for every single row returned from the stored procedure.
I wonder if these lookups in web.config are somehow optimized/cached?
If you're using ConfigurationManager
to access AppSettings
values, these are cached after the 1st time they're accessed. So the first time you access ConfigurationManager.AppSettings["MyValue"]
, it's read from disk, after that it's read from cache.