Recently I was working on a few demos in ASP.NET Core for an upcoming Pluralsight course, and I needed something that was able to generate cache-related response headers: Cache-Control, Expires, ETag and Last-Modified, and returns 304 – Not Modified or 412 – Precondition Failed responses when needed. Currently, that’s not included – there’s a ResponseCaching attribute available in ASP.NET Core MVC that can be used to annotate actions with and will result in the generation of a Cache-Control and Expires header, but as it doesn’t generate ETags (strong nor weak), it shouldn’t be used for validation.
In other words: it supports the cache Expiration model, but not the Validation model (more on that can be found here). I needed more, and figured I wouldn’t be the only one. And with that, the Marvin.Cache.Headers middleware was born
Marvin.Cache.Headers is ASP.NET Core middleware that adds HttpCache headers to responses (Cache-Control, Expires, ETag, Last-Modified), and implements cache expiration & validation models.