There is another thread where I got the answer for this
Prevent Caching in ASP.NET MVC for specific actions using an attribute
My solution (.Net 6 MVC) was the one below:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
namespace YourSolutionName.Web.Mvc.Controllers.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.GetTypedHeaders().CacheControl =
new Microsoft.Net.Http.Headers.CacheControlHeaderValue()
{
NoStore = true,
NoCache = true,
};
base.OnResultExecuting(filterContext);
}
}
}
And then adding the [NoCache] to the controllers I wanted.
I choose this because it provided a finer control over where I wanted to disable the caching, but if you would like to do it for the whole solution,
it ca be done with middleware (on Startup.cs)
https://learn.microsoft.com/en-us/aspnet/core/performance/caching/middleware?view=aspnetcore-7.0
app.UseResponseCaching();
app.Use(async (context, next) =>
{
context.Response.GetTypedHeaders().CacheControl =
new Microsoft.Net.Http.Headers.CacheControlHeaderValue()
{
NoStore = true,
NoCache = true,
};
await next();
});