Asp.net 核心 2.2 响应缓存,无法将 must-revalidate 添加到 cache-control 响应 header
Asp.net core 2.2 response caching, cannot add must-revalidate to cache-control response header
我正在使用以下响应缓存设置:
services.AddMvc(options =>
{
options.CacheProfiles.Add("HomePage", new CacheProfile()
{
Duration = Constants.HomePageOutputCacheInSeconds,
Location = ResponseCacheLocation.Any,
VaryByHeader = HttpCacheProfileProvider.CacheKeyHeader
});
options.CacheProfiles.Add("Article", new CacheProfile()
{
Duration = Constants.ArticleOutputCacheInSeconds,
Location = ResponseCacheLocation.Any,
VaryByHeader = HttpCacheProfileProvider.CacheKeyHeader
});
options.CacheProfiles.Add("Default", new CacheProfile()
{
Duration = Constants.DefaultOutputCacheInSeconds,
Location = ResponseCacheLocation.Any,
VaryByHeader = HttpCacheProfileProvider.CacheKeyHeader
});
}).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
services.AddMemoryCache();
services.AddResponseCaching();
在配置部分我设置:
app.UseResponseCaching();
和控制器:
[Route("", Name = "DesktopHome")]
[ResponseCache(CacheProfileName = "HomePage", Order = int.MaxValue)]
public async Task<IActionResult> Index()
一切正常。 Cache-Control:public, max-age:10
附加在 headers 中,但我也想设置 must-revalidate 和 max-stale-cache 属性,但我找不到 属性 来完成它。
属性 在 CacheProfiles 设置、ResponseCacheAttribute 和 app.UseResponseCaching 设置中不可用。
这可能吗?
除了在Cacheprofile中设置外,还可以直接使用Response来设置:
public async Task<IActionResult> Index()
{
Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
{
Public = true,
MaxAge = TimeSpan.FromSeconds(600),
MustRevalidate = true,
MaxStale = true
};
return View();
}
或者您可以在官方网站上查看Response Caching Middleware。
我正在使用以下响应缓存设置:
services.AddMvc(options =>
{
options.CacheProfiles.Add("HomePage", new CacheProfile()
{
Duration = Constants.HomePageOutputCacheInSeconds,
Location = ResponseCacheLocation.Any,
VaryByHeader = HttpCacheProfileProvider.CacheKeyHeader
});
options.CacheProfiles.Add("Article", new CacheProfile()
{
Duration = Constants.ArticleOutputCacheInSeconds,
Location = ResponseCacheLocation.Any,
VaryByHeader = HttpCacheProfileProvider.CacheKeyHeader
});
options.CacheProfiles.Add("Default", new CacheProfile()
{
Duration = Constants.DefaultOutputCacheInSeconds,
Location = ResponseCacheLocation.Any,
VaryByHeader = HttpCacheProfileProvider.CacheKeyHeader
});
}).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
services.AddMemoryCache();
services.AddResponseCaching();
在配置部分我设置:
app.UseResponseCaching();
和控制器:
[Route("", Name = "DesktopHome")]
[ResponseCache(CacheProfileName = "HomePage", Order = int.MaxValue)]
public async Task<IActionResult> Index()
一切正常。 Cache-Control:public, max-age:10
附加在 headers 中,但我也想设置 must-revalidate 和 max-stale-cache 属性,但我找不到 属性 来完成它。
属性 在 CacheProfiles 设置、ResponseCacheAttribute 和 app.UseResponseCaching 设置中不可用。
这可能吗?
除了在Cacheprofile中设置外,还可以直接使用Response来设置:
public async Task<IActionResult> Index()
{
Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
{
Public = true,
MaxAge = TimeSpan.FromSeconds(600),
MustRevalidate = true,
MaxStale = true
};
return View();
}
或者您可以在官方网站上查看Response Caching Middleware。