aliostad / CacheCow

An implementation of HTTP Caching in .NET Core and 4.5.2+ for both the client and the server
MIT License
847 stars 172 forks source link

NoCache option for WebApi #262

Closed bbodenmiller closed 3 years ago

bbodenmiller commented 3 years ago

I see I can do [HttpCache(DefaultExpirySeconds = 0)] but how can I do something like [HttpCache(NoCache = true)] and have CacheCow set cache-control: no-cache header?

aliostad commented 3 years ago

Hi, I see. I have mainly covered cases for caching but obviously you would like to make it easier to be able to send no-cache and no-store for non-cacheable stuff.

Would it work for you if I change it so that setting it to a negative number would send no-cache and no-store and Pragma?

Cheers Ali

bbodenmiller commented 3 years ago

I actually don't want no-store. What I'm looking to accomplish is to allow my response to be cached but to require revalidation on each use. If validation passes, use cached version.

https://jakearchibald.com/2016/caching-best-practices/ - pattern 2

aliostad commented 3 years ago

Well, setting the value to 0 will essentially mean exactly the same: the resource can be cached but must be validated. Adding no-cache would not make any difference.

Does this make sense?

bbodenmiller commented 3 years ago

Yes I will try that. Isn't there some minor differences like setting expires means can't be used without validation even if offline but using no-cache without express it can be used still if offline?

aliostad commented 3 years ago

Well, you can use must-revalidiate (possible via CacheCow) which does that and for stale cache it MUST retrieve - last time I checked but pretty sure.

aliostad commented 3 years ago

Hi @bbodenmiller are you happy with the option provided?

aliostad commented 3 years ago

I assumed you are happy due to lack of response.