You are browsing a read-only backup copy of Wikitech. The live site can be found at


From Wikitech-static
Revision as of 09:45, 25 July 2016 by imported>Ema
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The xkey Varnish module adds secondary hashes to objects, allowing fast purges of objects with the same key. Keys should preferably be set by the application in the xkey response header. Multiple keys can be specified per header line with a space separator:

Server: Apache/2.2.15
xkey: 8155054 166412 234323

or in multiple xkey response headers:

Server: Apache/2.2.15
xkey: 8155054
xkey: 166412
xkey: 234323

Alternatively, keys can also be set in VCL:

sub vcl_backend_response {
    set beresp.http.xkey = "8155054 166412 234323";

A specific header such as xkey-purge can be used to purge objects with a certain key.

GET / HTTP/1.1
xkey-purge: 166412

And the actual purge can be implemented in VCL as follows:

import xkey;
sub vcl_recv {
    if (req.http.xkey-purge) {
        if (xkey.purge(req.http.xkey-purge) != 0) {
            return (synth(200, "Purged"));
        } else {
            return (synth(404, "Key not found"));

vmod_xkey supports two different type of purges: normal ones and softpurges. Soft purges differ from purges in that they reset an object's TTL but keep it available for grace mode and conditional requests. Conversely, normal purges immediately purge the matching objects.

The function used for normal purges is: purge(STRING S). Soft purges can be performed with softpurge(STRING S). Both functions return the number of objects that were purged.

XKey is part of the varnish-modules vmod collection; Debian packages are also available.