由于想得脑袋都痛了,所以先放首页一回会儿,让大家一起讨论一下,还请dudu见谅
在设计Web应用程序的时候,性能可以说是最需要考虑的地方,使用cache是一个不错的选择,一直以来,我感觉Cache用来缓存小数量数据比较合适,但是今天在看Petshop的代码的时候 看到如下代码
if(Cache[categoryKey] != null){
// If the data is already cached, then used the cached copy
products.DataSource = (IList)Cache[categoryKey];
}else{
// If the data is not cached, then create a new products object and request the data
Product product = new Product();
IList productsByCategory = product.GetProductsByCategory(categoryKey);
// Store the results of the call in the Cache and set the time out to 12 hours
Cache.Add(categoryKey, productsByCategory, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration , CacheItemPriority.High, null);
products.DataSource = productsByCategory;
}
// If the data is already cached, then used the cached copy
products.DataSource = (IList)Cache[categoryKey];
}else{
// If the data is not cached, then create a new products object and request the data
Product product = new Product();
IList productsByCategory = product.GetProductsByCategory(categoryKey);
// Store the results of the call in the Cache and set the time out to 12 hours
Cache.Add(categoryKey, productsByCategory, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration , CacheItemPriority.High, null);
products.DataSource = productsByCategory;
}
本来 我对Cache认识还是蛮清晰的,现在 被这段代码弄糊涂了,cache到底 缓存多少数据库量比较合适。
几十条。
几百条。
几千条。
上万条。
还是存个几百万条。
是不是我想太多了??
还请大家帮我解除这个疑惑,
本文转自无心之柳.NET博客园博客,原文链接:http://www.cnblogs.com/9527/archive/2005/03/09/115425.html,如需转载请自行联系原作者