1
アクションが永続的にキャッシュされる最善の方法は、アプリケーションが再起動されるまでです。アプリケーションの存続期間中にアクション結果をキャッシュする
// Cache this result forever, it will reset on app restart
[OutputCache(Duration=999999)]
[ChildActionOnly]
public ActionResult Footer()
{
if (HttpContext.Application != null && HttpContext.Application.AllKeys.Contains("Version"))
return Content(HttpContext.Application["Version"].ToString());
return null;
}
これを行うより良い方法はありますか?
私は良い方法を知らない。独自の属性 'ForeverOutputCache'を作成することができます。これはコンストラクタで' Duration = Int32.MaxValue'を設定しますが、これはほぼ同じアプローチです。 –
@AlexanderYezutovはあなたの担当者のために答えとして、それを追加したいかもしれません;-) – Peter