VMOD purge - Varnish Purge Module

SYNOPSIS

import purge [as name] [from "path"]

INT hard()

INT soft(DURATION ttl, DURATION grace, DURATION keep)

DESCRIPTION

vmod_purge contains functions that offer a finer-grained control than return(purge) from vcl_recv{}. The functions can only be called from vcl_hit{} or vcl_miss{} and they should in general be used in both to ensure that all variants of a same object are taken care of.

EXAMPLE

sub vcl_recv {
    if (req.method == "PURGE") {
        if (client.ip !~ purge_acl) {
            return (synth(405));
        }
        return (hash);
    }
}

sub my_purge {
    set req.http.purged = purge.hard();
    if (req.http.purged == "0") {
        return (synth(404));
    }
    else {
        return (synth(200));
    }
}

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

sub vcl_miss {
    if (req.method == "PURGE") {
        call my_purge;
    }
}

sub vcl_synth {
    if (req.method == "PURGE") {
        if (req.http.purged) {
            set resp.http.purged = req.http.purged;
        }
        return (deliver);
    }
}

INT hard()

This is equivalent to return(purge) but explicitly called from vcl_hit{} and vcl_miss{}. It returns the number of purged objects.

Example:

set req.http.purged = purge.hard();

Restricted to: vcl_hit, vcl_miss.

INT soft(DURATION ttl, DURATION grace, DURATION keep)

INT soft(DURATION ttl=0, DURATION grace=-1, DURATION keep=-1)

Sets the ttl, grace and keep.

By default, ttl is set to 0 with grace and keep periods left untouched. Setting a negative value for grace or keep periods leaves them untouched. Setting all three parameters to 0 is equivalent to a hard purge. It returns the number of soft-purged objects.

Restricted to: vcl_hit, vcl_miss.

SEE ALSO