如何在IIS中为应用程序设置输出缓存?编程
答案 0 :(得分:2)
您可以使用OutputCache属性over action方法,如下所示
[OutputCache(Duration =20,VaryByParam ="ID")]
public ActionResult SearchRecord(int ID)
如果我们想在多个上使用相同类型的OutputCache属性 动作方法或多个控制器,然后我们可以使用CacheProfile 属性。 CacheProfile有几个优点。例如,我们可以 从一个中心更改多个位置的OutputCache属性 位置,无需重新编译我们的应用程序即可申请。加 system.web部分中的缓存部分,将包含 OutputCacheSettngs。在OutputCacheSettngs中,我们添加了 outputCacheProfiles具有名称和其他属性。
<caching> <outputCacheSettings> <outputCacheProfiles> <add name="CacheFor100Seconds" duration="100" varyByParam="none" location="Server"/> </outputCacheProfiles> </outputCacheSettings> </caching>
转到Action方法或控制器并添加CacheProfile属性 在OutputCache Action
中[OutputCache(CacheProfile = "CacheFor100Seconds")] public ActionResult MyAction()
来自http://www.c-sharpcorner.com/article/outputcache-action-filter-in-asp-net-mvc/