Skip to content

No clear way to disable ETag/Last-Modified behavior to force revalidation after max-age #142

Description

@mahmmoudkinawy

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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions