outputcachingを使用するアクションがあります
アクションによってレンダリングされるビューで、出力がキャッシュからのものであるかどうかを確認するために現在の時刻を表示します。
<!-- CacheCheck <%= DateTime.Now.ToString()%>-->
サイトに何らかのプレッシャーがかかると、web.configで指定されている限り、ページがキャッシュされないことに気付きました。キャッシュのコンテンツが削除されている理由を確認する方法はありますか?私は通常次のようなものを使用します:
HttpRuntime.Cache.Add(manufacturersCacheKey, manufacturers, null, DateTime.MaxValue, TimeSpan.FromDays(10), CacheItemPriority.Default, new CacheItemRemovedCallback(this.RemovedCallback));
public void RemovedCallback(String cacheKey, Object cacheValue, CacheItemRemovedReason reason)
{
_log.InfoFormat("RemovedCallback Cache Bereich {0} Grund: {1}", cacheKey, reason);
}
しかし、outputcachingでこれを行う方法が見つかりません。
これが私のコードです:
[OutputCache(CacheProfile = "HomeCaching")]
public ActionResult Index(HomeViewModel model)
これは、次のようにweb.configで設定されます。
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<clear />
<add name="HomeCaching" enabled="false" duration="120" varyByCustom="homecaching" location="Server" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
VariByCustomメソッドは次のように機能します。
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (arg.ToLower() == "homecaching")
{
string rval = "";
HttpCookie cookieBrowserOverride = context.Request.Cookies.Get(".ASPXBrowserOverride");
if (context.Request.Browser.IsMobileDevice && cookieBrowserOverride == null
|| !context.Request.Browser.IsMobileDevice && cookieBrowserOverride != null
)
{
rval = "mobile-";
}
rval += context.Request.Url.ToString();
HttpCookie cookieASPXAUTH = context.Request.Cookies.Get(".ASPXAUTH");
if (cookieASPXAUTH != null)
{
if (cookieASPXAUTH.Value.Length > 0)
{
rval = rval + "auth";
}
}
if (rval.Length > 0)
{
return rval;
}
return "";
}
return base.GetVaryByCustomString(context, arg);
}