Comment by jiehong

3 days ago

Is Vary really that ugly?

I’d say that it forces you to maybe parse and understand the headers that vary header.

Accept-Language is supposed to be parsed and matched according to RFC4647 in one of 3 ways. That part is rather complex, but it’s not Vary’s fault.

One major issue with Vary is that it makes cache coalescing very complicated. This is because you can't know whether two requests will share a response until you get that response. So for subsequent requests you need to decide if you should block it hoping that the response will satisfy it or if you should send it through pessimistically, possibly triggering a thundering herd effect on every cache rotation.

I'm not sure if it is possible to solve this nicely in a generic way, but it does make it a bit ugly.

  • This is not caused by Vary but by the app being so.. variable.

    If you segregate content-type/language by end-point then the variability goes away. But now you have a plethora of end-points. The complexity can get moved around, and in this particular case the complexity for the caching layer can be removed, but the complexity isn't gone.