Given that I have the following WCF service:
class LookUpService
{
public List<County> GetCounties(string state)
{
var db = new LookUpRepository();
return db.GetCounties(state);
}
}
class County
{
public string StateCode{get;set;}
public string CountyName{get;set;}
public int CountyCode{get;set;}
}
What will be the most efficient (or best) way to cache a state’s counties using weak references (or any other approach) so that we don’t hit the database every time we need to look up data.
Note that we will not have access to the HttpRuntime (and HttpContext).
For this scenario you’re going to want to use a
WeakReferencestyle hash table of sorts. None is available in the BCL (until 4.0) but there are several available online. I will be using the following for this sampleTry the following cdoe
As you can see, it’s not much different than using a normal
Dictionary<TKey,TValue>