varnish and http header
I'm a newbie to Varnish , and I wanted to know if Varnish supports caching with http header. We designed a Rest base web service , and I'm thinking about using Varnish to cache t开发者_如何学运维he results . How ever some of the request information (apikey) is passed via http header and I wanted to know if we Varnish can take it into account when examine the incoming request (vs query string) .
Yes you can. How should this API key be taken into account? If you want unique cache entries for every user, cache is only used if a specific user requests the same data more than once. You could get a long way without using a caching proxy like varnish by setting up the correct Cache-Control HTTP Response headers (although data freshness is not revalidated).
There are at least two approaches for this in Varnish;
Let your application return a HTTP-Response header Vary: apikey .This instructs any HTTP level cache (like varnish) to only reuse a cache result if the apikey request headers are the same.
Or, more efficiently, modify the vcl_hash function in your vcl config to take the apikey header into account.
sub vcl_hash { set req.hash += req.http.apikey; }
精彩评论