A data cache, generally by the data source, caching scheme, cache read to complete, now has an anonymous function, you can get the data source into anonymous functions. This allows you to declare a cache directly:
protected static CacheManager<Company> companyCache = new CacheManager<Company>(new SmsDatabaseCache<Company>(), (key) =>
{
return SmsDatabase.Instance.Context.Company.Where(c => c.ShortNumber == (string)key).SingleOrDefault();
});
Smsdatabasecache is a caching scheme, you can also use Simplecache,timeoutcache and so on to implement the Icache interface classes, because my icachemanager inherit from Icache, so you can also implement the level of even cache yo, For example:
Smsdatebasecache is a SmsDatabase.Instance.Context caching scheme that clears data operations when Linqcontextdispose.
Smsdatabasecache
public class SmsDatabaseCache<TData> : ICache<TData>
{
private Dictionary<object, TData> cache = new Dictionary<object, TData>();
public SmsDatabaseCache()
{
SmsDatabase.Instance.PreDisposing += (s, e) =>
{
cache.Clear();
};
}
public TData Get(object key)
{
return cache[key];
}
public void Set(object key, TData data)
{
cache[key] = data;
}
}