According to this page, I should enable the response caching middleware to use the ResponseCache
attribute on endpoints.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddResponseCaching(); // <--- here
var app = builder.Build();
app.UseHttpsRedirection();
// UseCors must be called before UseResponseCaching
//app.UseCors();
app.UseResponseCaching(); // <--- here
app.UseAuthorization();
app.MapControllers();
app.Run();
I only added the ResponseCache
attribute to my controller endpoints and forgot to add the above lines to enable and configure the response caching middleware. However, the endpoints did return the correct cache configuration.
Did I misunderstood the text in the page or this feature is enabled by default now?