KevinDockx / HttpCacheHeaders

ASP.NET Core middleware that adds HttpCache headers to responses (Cache-Control, Expires, ETag, Last-Modified), and implements cache expiration & validation models
MIT License
271 stars 57 forks source link

Marking for invalidation #104

Closed MarkBirch3D closed 1 year ago

MarkBirch3D commented 2 years ago

Less of an issue and more of a cry for help. This might not be the correct place for this but I don't know where else to turn to. I added validation caching to my api while following your advanced restful concern course on pluralSight (which was awesome!). While checking this github project, I saw that cache invalidation was now supported (it wasn't when the course was made).

I am trying to implement it by replicating what is done in StoreManipulationController (sample) in my own controller, but I can't seem to figure it out, and I am running out of ideas.

I added both IValidatorValueInvalidator and IStoreKeyAccessor to my controller's constructor. When going through a PUT request, I added the code to find the key from the storeKeyAccessor, but neither FindByKeyPart nor FindByCurrentResourcePath returns anything. When debugging, I can see that my _validatorValueInvalidator contains something though...

Any and all help is appreciated!

KevinDockx commented 2 years ago

Hi Mark,

could you provide me with a small code example (a small runnable project would be perfect)? I'll have a look :)

KR, Kevin

MarkBirch3D commented 2 years ago

Hello Kevin, Thanks a lot for the reply! While Trimming my project down to a bare-bones version for sharing purposes, I found out that it works for some of my controllers, but not with the one I was initially Testing with. I investigated for a while and still can't figure out why it won't work for this one controller...

I added you to my temporary repo that contains my code. I left only two controllers in there, one that works (Licenses) and the one that doesn't (TokenNotifications). I also included a postman file.

I am for sure missing some tiny detail or something, and I'm going to feel dumb about it, but that's just what this profession is sometimes!

Thank you so much for your help!

KevinDockx commented 2 years ago

You found a bug :-) The only difference I see is that your GET requests to /licenses are lowercase, while the requests to /TokenNotifications are mixed case. If I change the GET request to /tokennotifications (so: all lowercase), it works as expected.

I created a fix. By default, casing will now be ignored when searching for keys. If required, case can still be taken into account by passing through "false" as value for the (new) ignoreCase parameter for FindByKeyPart/FindByCurrentResourcePath.

Commit: https://github.com/KevinDockx/HttpCacheHeaders/commit/26acdb52641ff006f996770949ab978e6da29fc3

I'll push a new version to NuGet.

Thanks for finding this! :)

KevinDockx commented 2 years ago

https://www.nuget.org/packages/Marvin.Cache.Headers/6.1.0

MarkBirch3D commented 2 years ago

Awesome! thanks a lot for your help!