varnishd -a addr:8001,addr:8002 -- Share same cache?

Shenton, Chris (HQ-LM020)[INDYNE INC] chris.shenton at nasa.gov
Mon Mar 7 22:36:41 CET 2011


To accommodate our hosting environment, we need to run varnish on two different ports, but we want to make both use the same cache.  That is, if I have:

  varnishd -a 127.0.0.1:8001,127.0.0.1:8002

I want client requests to both both 8001 and 8002 ports to share the content of the same cache. So if one client hits :8002 with a URL and another later hits :8001 with the same URL, I want the latter to retrieve the content cached by the former request.

In my testing, however, it seems that this is not happening, that the doc is getting cached once per varnishd port.

First on 8001, we see it's not from cache as this is the first request:

> $ curl -v  -o /dev/null http://localhost:8001/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421263

Then to 8002 where I'd hope it was returned from cache, but the X-Varnish and Age headers indicate it's not:

> $ curl -v  -o /dev/null http://localhost:8002/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421264

Now back to the first port, 8001, and we see it is in fact returned from cache:

> $ curl -v  -o /dev/null http://localhost:8001/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421265 730421263

And if I try 8002 again, it's also returned from cache:

> $ curl -v  -o /dev/null http://localhost:8002/ 2>&1 | grep X-Varnish:
> < X-Varnish: 730421266 730421264

Is there a way to make both ports share the same hash? I'm guessing the listening port is included with the hash key so that's why it appears each URL is being stored separately.  If so, is there a way to remove the listening port from the hash key the document is stored under? Or would that even work? 

Thanks.





More information about the varnish-misc mailing list