我尝试在 asp.net core 项目中实现响应缓存,但它不起作用。这是 startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCaching();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCaching();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器。
[ResponseCache(Duration = 30)]
public IActionResult Index()
{
ViewBag.IsMobile = RequestExtensions.IsMobileBrowser(ContextAccessor.HttpContext.Request);
return View();
}
Run Code Online (Sandbox Code Playgroud)
但仍然缓存控制标头 id
cache-control ?no-cache, no-store
Run Code Online (Sandbox Code Playgroud)
我缺少的地方请帮助。此响应缓存不起作用,我从 Microsoft 文档中获取指导