开发者

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;

  1. 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.

  2. 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; }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜