varnish / varnish-modules

Collection of Varnish Cache modules (vmods) by Varnish Software
Other
182 stars 86 forks source link

control the xkey purge action #41

Closed redbox-cdn closed 8 years ago

redbox-cdn commented 8 years ago

Hi

Is there way to control the xkey purge action ?

I would like to purge object only include domainname.com AND req.http.xkey. if not include domainname, action is skipped.

Background: in case of multi host, the other hostname or sites content has purged when xkey header is same value.

EX: test1.com test.txt xkey header = keyherder

test2.com test.txt xkey header = keyherder

So I considered following code using BAN but I do not know how to use the xkey module.

In case of BAN


if (req.method == "XKEY") {
                ban("obj.http.host ~ "+ req.http.host +" && obj.http.xkey ~ " + req.http.xkey);
                return(synth(200, "OK."));
           }

In case of xkey Purge

xkey.purge((std.strstr("domainname.com", obj.http.host )  && req.http.xkey);
*it is syntax error
daghf commented 8 years ago

Hi

xkey only lets you purge content based on the specific key that was associated when the object was inserted into cache.

If test1.com/foo and test2.com/foo both have the key /foo, they will necessarily both be purged if you issue a purge on that key.

The solution here is to make your keys more specific and include the host header as well. So for your example, test1.com/foo sets xkey: test1.com/foo and likewise for test2.com/foo which would set xkey: test2.com/foo. This will then permit you to invalidate each of them separately via invoking xkey.purge() with the correct host and URL.

thangamani-arun commented 7 years ago

Hi @daghf @redbox-cdn ,

I'm trying to test purge using VCL implemented Xkey headers. Could you please share the example VCL config ? I can set req.http.key in VCL file.