【发布时间】:2012-10-28 12:50:08
【问题描述】:
编辑:
有没有办法监控缓存?
我决定实施缓存来提高产品页面的性能。目前,每个产品页面至少包含 3000 个条目。
使用缓存,这应该会大大缩短这些页面的加载时间。但我不确定我的实现是否有效,因为我已经在数据库中添加了新记录,并且这些更改会反映在浏览器中。
任何想法为什么缓存不起作用?
public class Acquire
{
public class All
{
public WebGrid Products(String Range, String Category)
{
String cacheItemKey = Range + Category;
bool cacheHit = true;
Grid = WebCache.Get(cacheItemKey);
if (Grid == null)
cacheHit = false;
if (cacheHit == false)
{
results = database.Products.Where(
x => x.Range == Range && x.Category == Category);
Grid = new WebGrid(results, canPage: false);
// Add it to the Cache.
WebCache.Set(cacheItemKey, Grid, 1, false);
}
return Grid;
}
}
}
如果您想知道为什么它包含在类和方法中;主要是为了保持页面美观整洁,减少代码重复,防止出错。
【问题讨论】:
标签: c# .net caching razor webmatrix