Varnish and http header

I am new to Varnish and I wanted to know if Varnish supports http header caching. We have developed the base web service Rest, and I am thinking of using Varnish to cache the results. As soon as part of the request information (apikey) is transmitted via the HTTP header, and I wanted to know if we, Varnish, could take this into account when checking the incoming request (request and request string).

+3
source share
1 answer

Yes, you can. How should this API key be considered? If you need unique cache entries for each user, the cache is used only if a particular user requests the same data more than once. You can go a long way without using a caching proxy server, such as varnish, by setting the correct Cache-Control HTTP response headers (although data freshness is not checked).

There are at least two approaches to varnish:

  • Let your application return the HTTP-Response Vary: apikey header. It instructs any HTTP level cache (e.g. varnish) to only reuse the result of the cache if the headers of the apikey request match.

  • Or, more efficiently, modify the vcl_hash function in your vcl configuration to take into account the apikey header.

    sub vcl_hash {set req.hash + = req.http.apikey; }

+10
source

All Articles