Summary
I’m using Marvin.Cache.Headers to set client-side caching with a max-age of 60 seconds. My goal is:
After the max-age expires, I want the client to send a request, and the server should re-execute the controller and return fresh content (200 OK), even if the data hasn’t changed.
Currently, this doesn't happen. The response is still 304 Not Modified, and the controller is not hit even after the cache duration has expired.
Setup
builder.Services.AddHttpCacheHeaders(
expirationModelOptions =>
{
expirationModelOptions.MaxAge = 60;
expirationModelOptions.CacheLocation = CacheLocation.Public;
},
validationModelOptions =>
{
validationModelOptions.MustRevalidate = true;
},
middlewareOptionsAction =>
{
middlewareOptionsAction.DisableGlobalHeaderGeneration = true;
}
);
var app = builder.Build();
app.UseRouting();
app.UseHttpCacheHeaders();
app.MapControllers();
app.Run();
[HttpGet("{id}")]
[HttpCacheExpiration]
[HttpCacheValidation]
public IActionResult GetItem(int id)
{
var item = new { Id = id, Name = Configuration.GetValue<string>("Name") };
return Ok(item);
}
Summary
I’m using Marvin.Cache.Headers to set client-side caching with a max-age of 60 seconds. My goal is:
Currently, this doesn't happen. The response is still
304 Not Modified, and the controller is not hit even after the cache duration has expired.Setup