When varnish invalidates cache via Purge
and Ban
, does it use the hash keys defined in vcl_hash to help looking up the objects? If I'm going to invalidate cache by a custom header obj.http.page_id
instead of obj.http.url
recommended by this article, would it affect the performance since the hash keys don't use http.page_id
? I don't see any mention of this in the document, but want to make it clear before using the new method.
sub vcl_recv {
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return (synth(405, "Not allowed."));
}
ban("obj.http.url ~ ^" + req.url);
return (purge);
}
}
sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
}
If you're doing a BAN, then it does not need to match the hash, since the BAN is going to apply when the object(s) are looked up.
A PURGE however will do a normal object lookup, and so you could not do it using an alternate key.