Varnish Cache Plus

Advanced purge (softpurge)

DESCRIPTION

Softpurge is cache invalidation in Varnish that reduces TTL but keeps the grace value of a resource. This makes it possible to serve stale content to users if the backend is unavailable and fresh content can not be fetched.

vcl 4.0;
import softpurge;

backend default { .host = "192.0.2.11"; .port = "8080"; }

sub vcl_backend_response {
    # Set object grace so we keep them around after TTL has expired.
    set beresp.grace = 10m;
}

sub softpurge {
    if (req.method == "PURGE") {
        softpurge.softpurge();
        return (synth(200, "Successful softpurge"));
    }
}

sub vcl_hit {
	call softpurge;
}

sub vcl_miss {
	call softpurge;
}

API

softpurge

VOID softpurge()

The only function of the vmod performs a soft purge, setting the TTL of the object to 0. It must be called both from vcl_hit and vcl_miss to make sure all variants of the chosen object are reset.

Example:

    sub vcl_hit {
        if (req.method == "PURGE") {
            softpurge.softpurge();
        }
    }

Availability

vmod_softpurge is bundled directly in the varnish-plus package.