我正在使用以下设置进行响应缓存:
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
附加在标题中,但我也想设置 must-revalidate 和 max-stale-cache 属性,但我找不到属性来完成它。
属性在 CacheProfiles 设置、ResponseCacheAttribute 和 app.UseResponseCaching 设置中均不可用。
那可能吗?