1

We're caching 404 for images as sometimes our app would be released ahead of the actual images and would like to be able to clear them based on status code rather than ALL the images or specific images one by one.

However I am new to Varnish an unsure whether that is doable as I couldn't find any specific documentation on clearing based on status code.

son9o
  • 33
  • 5

2 Answers2

1

you can either PURGE and image or BAN it. Purging: it deletes a specific object from cache and to do so you will need to know the host and the URL of the specific object you want to purge. Banning: to ban you can use regex and for your use case something among those lines should work. In vcl_recv:

if (req.method == "BAN") {
    ban("req.status == "404");
}
  • Thanks for posting, however trying that in varnishadmn req.status is not a valid ban-able object – son9o Mar 20 '18 at 09:54
  • I've noticed you actually work for varnish, so perhaps you can find out whether there is a way of removing a ban list entry or a flushing the whole list without restarting the varnish service? – son9o Mar 20 '18 at 10:11
  • Shouldn't it be `req.status == 404` by http standard it should be an integer? However I have seen not all systems adhere to that, for example AWS S3 it's a String. – OZZIE Jan 28 '21 at 09:09
1

It seems that purge method is just an overlay on vcl's ban. Using varnishadmn to test I've found to purge specific status, code only obj.status is accepted.

varnishadm ban obj.status == 404

verify with:

varnishadm ban.list
son9o
  • 33
  • 5