私はこのアクションメソッドを持っています:
[OutputCache(Duration = 2,
Location = OutputCacheLocation.Any,
VaryByHeader = "Accept-Charset")]
public ActionResult Index()
{
return View();
}
そして、生成された応答は次のとおりです。
Cache-Control:public, max-age=2
Content-Length:5164
Content-Type:text/html; charset=utf-8
Date:Wed, 28 Sep 2011 16:30:33 GMT
Expires:Wed, 28 Sep 2011 16:30:35 GMT
Last-Modified:Wed, 28 Sep 2011 16:30:33 GMT
Server:Microsoft-IIS/7.5
Vary:*
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
X-Powered-By:ASP.NET
Vary
ヘッダーに代わりにアスタリスクが表示されるのはなぜAccept-Charset
ですか?
OutputCacheAttribute
応答に影響を与えますが、実際には、ヘッダーExpires
とCache-Control:max-age=n
ヘッダーはDuration
引数に依存し、 Cache-Control:public
//は引数に依存しprivate
ます。no-cache
Location
OutputCacheAttribute
何が起こっているかを確認するためのラッパーを作成しました。
public class CustomOutputCacheAttribute:OutputCacheAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
base.OnResultExecuted(filterContext);
Dictionary<String, String> headers = new Dictionary<string, string>();
foreach (var header in filterContext.HttpContext.Response.Headers.AllKeys)
headers.Add(header, filterContext.HttpContext.Response.Headers[header]);
Debugger.Break();
}
}
ヘッダーは区切りに表示されていないので、おそらくOutputCacheAttribute
configureが何をするのでしょうかHttpContext.Current.Response.Cache
。
どのようfilterContext.HttpContext.Response.Cache.VaryByHeaders.UserCharSet
にtrueであるか、たとえばfalsefilterContext.HttpContext.Response.Cache.VaryByHeaders.AcceptTypes
であるかはわかりますが、ヘッダーには常に*と表示されます。Vary
可能な値は、のプロパティとしてリストされている4つの値だけfilterContext.HttpContext.Response.Cache.VaryByHeaders
でしょうか?
乾杯。