Vary

The Vary header defines how to decide whether a cached response can be used or not. It contains a comma-separated list of headers, which must not change, in order to decide whether the cache can be used.

Let's take these two HTTP responses, for example:

HTTP/1.1 200 OKApp-Target: desktop....
HTTP/1.1 200 OKApp-Target: mobile....

Both the responses are the same, except the App-Target header. If you add caching, a desktop or mobile request will lead to the same payload being served if cached.

Now, if the responses are modified, like in the following snippets, to add the Vary header, each kind of App-Target will not reuse the cache of the other one:

HTTP/1.1 200 OKApp-Target: desktopVary: App-Target....
HTTP/1.1 200 OKApp-Target: ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.