Possible to detect a previous xkey softpurge?

Batanun B batanun at hotmail.com
Thu Sep 3 16:55:05 UTC 2020


Hi,

I'm not sure how that "no-grace" header would be set. The softpurge could theoretically impact hundred of URLs, and what we would like is that any requests for these URLs after the softpurge should include a special header when talking with the backend.

Skipping grace in general, and sending that special header to all requests to the backend, is not what we want. 

But now I am thinking of an alternative, that might give us somewhat what we want while being much simpler and not needing to know if a softpurge has happened or not. Since we really only need to do this in a short time period after a softpurge, and the softpurge sets ttl to zero, then we can skip the "after a softpurge" requirement and simply check if the ttl recently expired. As far as I understand it, when the ttl has expired, the obj.ttl is a negative value indicating how many seconds since the ttl expired. So 15 seconds after the ttl, it would be -15s. Then we can have something like this in in vcl_hit:

```
if (obj.ttl > -15s) {
	set req.http.X-my-backend-skip-cache = "true";
	return (miss);
}
```

I can't check this right now, from the computer I am at. But it should work, right? Then the only "false positives" we will end up with are the requests that happen to come in within 15 seconds of the regular ttl expiring. But if we get the cache invalidation to work fully (including in the backend), then we should be able to increase the regular ttl higher than the current 5s, and then this false positive should happen much more rarely.


Guillaume Quintard <guillaume at varnish-software.com> wrote:
>
> Hi, 
> 
> You can't detect a softpurge, but you can tell Varnish to ignore grace:
> 
> ```
> sub vcl_recv {
>     if (req.http.no-grace) {
>         set req.grace = 0s;
>     }
> }
> ```
> 
> the softpurge kill the ttl at the object level, and this kills the grace at the request level, so Varnish will reach out to the backend.
> 
> But note that it will also do the same even without a prior softpurge, it just needs an expired ttl.
> 


More information about the varnish-misc mailing list