magneto-varnish icon indicating copy to clipboard operation
magneto-varnish copied to clipboard

Clear Varnish Cache when using shared Varnish server

Open CyberNBD opened this issue 13 years ago • 9 comments

When using one Varnish server for multiple domains / magento shops, using the clear Varnish cache within one shop will also clear cache for other shops on the Varnish server. Even when shops are on differend backend servers.

Using magento 1.6.1 and Varnish 2.1

CyberNBD avatar Jan 11 '12 22:01 CyberNBD

I've attempted to solve this in my branch:

https://github.com/allardhoeve/magneto-varnish

Please pull from there if you want and give it a try.

allardhoeve avatar Jan 19 '12 14:01 allardhoeve

Seems to work for individual URL purges when updating articles or pages, but when using cache management for full store cache flush it seems there's still no host header sent.

Product update: 13 RxRequest c PURGE 13 RxURL c /electronics/cell-phones/htc-touch-diamond.html 13 RxProtocol c HTTP/1.1 13 RxHeader c Accept: / 13 RxHeader c Host: demo.lab.*****.nl 13 VCL_call c recv 13 VCL_acl c MATCH trusted 172.16.143.47 0 Debug - "VCL_error(200, PURGE)"

Store cache flush: 13 RxRequest c PURGE 13 RxURL c /.* 13 RxProtocol c HTTP/1.1 13 RxHeader c Host: 172.16.143.76 13 RxHeader c Accept: / 13 VCL_call c recv 13 VCL_acl c MATCH trusted 172.16.143.47 0 Debug - "VCL_error(200, PURGE)"

172.16.143.76 is varnish cluster virtual ip so whole cache is flushed.

CyberNBD avatar Jan 19 '12 19:01 CyberNBD

Yes, I haven't coded that part yet. I have no idea how to list all the stores in the backend. But I'm sure I'll get around to it.

At least the categories, etc. are flushed now. The rest should be relatively easy.

allardhoeve avatar Jan 19 '12 20:01 allardhoeve

Try again with the latest commit. It sends headers now. I haven't tested extensively, but I see them in varnishlog. I need to optimize the code though.

Help appreciated.

allardhoeve avatar Jan 19 '12 22:01 allardhoeve

The headers indeed appear in varnishlog, but it still seems to clear everything here on my lab setup.

CyberNBD avatar Jan 22 '12 00:01 CyberNBD

This is a VCL issue. Match req.http.host in your PURGE regexp like so:

purge("req.url ~ " + req.url + " && req.http.host == " + req.http.host);

Haven't tested, because I'm om Varnish 3.0 and you seem to be on Varnish 2.x. Fiddle with the config a bit if you will.

allardhoeve avatar Jan 22 '12 13:01 allardhoeve

Indeed a VCL issue, seems i somehow went back to an older VCL which didn't match the req.http.host

purge("req.url ~ " req.url " && req.http.host == " req.http.host); works

Thanks.

CyberNBD avatar Jan 23 '12 21:01 CyberNBD

allardhoeve, your branch gives a 404. Would like to see your solution. Maybe i can use it with the problem i'v got.

Shared varnish servers with multidomain shops and serveraliases.

thx,

Coen

coenswaans avatar Mar 06 '12 09:03 coenswaans

Hey Coen,

Yeah, my branch moved :)

I'll try and reupload the branch.

Best,

Allard

allardhoeve avatar Mar 06 '12 09:03 allardhoeve