views:

633

answers:

3

I am writing out a navigation structure of categories. Each category has an ID, that is located in a 3rd party search tool. At either app start, or at various intervals, I need to get the caetegories and their id's, and store them in a dictionary (or some other way) so that I can access them for link rewriting from id to name.

A: 

Store the Dictionary in a XML file using a format that looks something like this and read it when you need to do your re-writing

<nodes>
<node id="1">Some Nav Data</node>
</nodes>

You then have 2 options , write a separate process that will update the file at specific intervals or your current process can update the file after a set interval.

If you feel that loading and parsing XML is overkill think about serializing a class to disk that contains a simple hash table or dictionary.

RC1140
A: 

How many settins are you talking about? Why do you need a cache rather than just using an in-memory dictionary with a background thread to reload it periodically?

If you need a cache, you could look at the caching application block in EntLib. You can set an expiry interval and then handle an even on expiry to repopulate the cache. But frankly that sounds overblown for your requirements.

serialhobbyist
There would be approx 70 categories with their associated ids
mickyjtwin
Essentially, on a search, within the results will come a collection of id's relative to the search criteria. These id's will be a category name. I need to map the id to the name so I can write a friendly url. Similarly coming the other way, an incoming request needs to map the name back. This needs to be available for the life of the app, and will not change very often, i.e. days, even weeks.
mickyjtwin
It doesn't sound like a lot of data - is there any reason you can't just keep it in memory? Or are you looking for other facilities?
serialhobbyist
A: 

Caching is a super big topic! You could use a local cache if you are in a web project. You could use HttpContext.Current.Cache if you are in a windows environment (though you don't really need cache in a windows app). If you are spanning more than one web server then you might look to the power of MemCached or MemCached Win32. If you don't mind using new stuff you could also take a look at Velocity (which is MS's answer to MemCache's superiority for the past several years in the caching arena).

Here are some SO posts that might interest you:

http://stackoverflow.com/questions/21870/system-web-caching-vs-enterprise-library-caching-block

http://stackoverflow.com/questions/1183814/running-a-asp-net-website-with-ms-sql-server-when-should-i-worry-about-scalabil

Andrew Siemer