Boost grace period on varnish when error 500 ocurred

887 views Asked by At

I use the following code to boost the grace period in varnish when i receive error 500 from the backend:

# If backend returns 500 error then boost the cache grace period...
if (beresp.status == 500) {
   set beresp.grace = 1m;
return (retry);
}

But i want only boost the grace period when i have another cache, if i don't have cache, i just want to cache the error.

Backend response configuration "vcl_backend_response" for the cache:

# Cache 1 day
if(bereq.url ~ "^/"){
    set beresp.http.X-cachePath = beresp.http.X-cachePath +  "1d::";
    unset beresp.http.set-cookie;
    unset beresp.http.Cache-Control;
    set beresp.ttl = 1d;
    set beresp.grace = 1h;
    return (deliver);
}

Is this possible do it with varnish 4 ?

Thanks for all !

1

There are 1 answers

0
Redithion On

I think what you are looking for is Saint Mode. Here is an example.

What Saint Mode does is similarly to Grace Mode but in a different situation, while Grace Mode acts when backend is sick or takes too long to respond, Saint Mode acts when you don't like the backend response.

In this case, the 500 error is the response that you don't like.

It's a pitty that Saint Mode has been removed from Varnish core in version 4. Despite not being as easy as in Varnish 3, here is a VMOD for Saint Mode in Varnish 4