标签:style blog io ar os 使用 sp strong 文件
启用页面缓存
在MVC3中如果要启用页面缓存,需要在页面对应的Action前面加上一个OutputCache属性。
@{
ViewBag.Title = "主页";
}
<!DOCTYPE html>
<html>
<head>
<title>页面缓存</title>
</head>
<body>
现在时间:@DateTime.Now.ToString("T")
</body>
</html>
[OutputCache(Duration=5, VaryByParam="none")]
public ActionResult Index()
{
return View();
}
缓存的位置
可以通过设置缓存的Location属性,决定将缓存放置在何处。
Location可以设置的属性为(Any Client Downstream Server None ServerAndClient)
Location的默认值为Any。一般推荐将用户的信息存储在Client端,一些公用的信息存储在Server端。
加上Location应该是这样的。
[OutputCache(Duration=5, VaryByParam="none",Location=OutputCacheLocation.Client ,NoStore=true)]
public ActionResult Index()
{
return View();
}
当我们需要对多个Action进行统一的设置时,可以在web.config文件中统一配置后进行应用即可。
在web.config中配置下Caching节点
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="Cache1Hour" duration="3600" varyByParam="none"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>[OutputCache(CacheProfile="Cache1Hour")]
public ActionResult Index()
{
return View();
}
标签:style blog io ar os 使用 sp strong 文件
原文地址:http://blog.csdn.net/wangboxian/article/details/41575907