I've got Varnish in front of multiple webservers, I can run them as native to varnish or through upstream checks via nginx, but only static content is cached (no surprise), also respecting query strings i.e.
/main.css?v=1
and /main.css?=v2
are cached separately
I update servers one by one, in fact, all this cannot be done at exactly the same time without downtime, general deployment thing.
If main.css
gets updated on one backend and I send request according to the new webpage version to the varnish and request /main.css?=v2
, it may still look for file on the machine which has old version and where main.css
hasn't been updated yet, so, now I am getting v1 in the cache as v2 and there is nothing I can do, unless TTL expires (which is too late).
I can manually invalidate cache via requests, that's ok.
Is there any automated solution without manual interfering on rewriting software for feedback to varnish? like:
- Is it possible, to expire cache when backend comes up, after probe is good?
- anything else?
Thanks
If you load this code, or adapted for your varnish version, you can then send requests of type PURGE, with the request URL matching the thing you want to purge, to wipe the item from varnish cache. You can use this to basically automate selectively purging at the end of the deployment process against your Varnish servers, via cURL commands or similar.
https://github.com/dreamhost/varnish-vcl-collection/blob/master/lib/purge.vcl