kornelski / http-cache-semantics

RFC 7234 in JavaScript. Parses HTTP headers to correctly compute cacheability of responses, even in complex cases
http://httpwg.org/specs/rfc7234.html
BSD 2-Clause "Simplified" License
244 stars 27 forks source link

Check revalidated response is storable in example #4

Closed lukechilds closed 7 years ago

lukechilds commented 7 years ago

It's possible that a revalidated response should not be stored. e.g has Cache-Control: no-store header. Therefore it should be explicitly checked to see if it's storable rather than assuming it still is.

kornelski commented 7 years ago

Thanks. That's a good point.

but this simple solution leaves the old response in the cache, and I'm not sure if that's correct either. I suppose the ideal solution would also remove the old entry from the cache, but that starts getting into a bit too much detail for a basic example :/

lukechilds commented 7 years ago

Yeah, not a particularly likely scenario but just thought I'd bring it up as it is technically violating the RFC. (storing a non storable response)

I don't think keeping a stale cache entry is a violation of the RFC but if you wanted to account for it it's only two extra lines:

} else {
  letsPretendThisIsSomeCache.del(newRequest.url);

But yeah, like I said, not a scenario that's particularly likely to occur so ¯\_(ツ)_/¯.

kornelski commented 7 years ago

Thanks. I'm going to leave it as-is. Hopefully people won't copy the example literally.