我有这个动作方法:
[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
andCache-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
是真的,例如filterContext.HttpContext.Response.Cache.VaryByHeaders.AcceptTypes
是假的,但Vary
标题总是说*。
我想知道是否唯一可能的值是列为 的属性的四个值filterContext.HttpContext.Response.Cache.VaryByHeaders
,可以吗?
干杯。