<div dir="ltr">I am using multiple hash_data calls to customize the hash key. I need to cache potentially three different version of the page.<div><br></div><div>My problem is how do I purge the items. I have tried implementing purge; in recv, hit, miss functions like Varnish docs show but still not working.</div>
<div><br></div><div>I have tried implementing ban using a regex or == on the URL.</div><div><br></div><div>Below is my VCL hash function. How do I purge a URL that is hashed with key...</div><div><br></div><div>"/mysection/mystory.htmlwww.example.com_preview_mobile"</div>
<div><br></div><div>I had this working prior to Varnish 3 but seems to have stopped working after that.</div><div><br></div><div>##VCL Hash function below</div><div><br></div><div>vcl_hash {</div><div><br></div><div><div>
hash_data(req.url);</div><div> if (req.http.host) {</div><div> hash_data(req.http.host);</div>
<div> } else {</div><div> hash_data(server.ip);</div><div> }</div><div><br></div><div> #if(req.http.Accept-Encoding) {</div><div> # set req.hash += req.http.Accept-Encoding;</div><div> #}</div><div>
<br></div><div> ## /* Normalize Accept-Encoding to reduce effects of Vary: Accept-Encoding</div><div> ## (cf. <a href="http://varnish-cache.org/wiki/FAQ/Compression" target="_blank">http://varnish-cache.org/wiki/FAQ/Compression</a>)</div>
<div> ## Also note that Vary: User-Agent is considered harmful */</div><div> if (req.http.Accept-Encoding) {</div><div> if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {</div><div> // Don't compress already-compressed files</div>
<div> remove req.http.Accept-Encoding;</div><div> }</div><div> elsif (req.http.Accept-Encoding ~ "gzip") {</div><div> set req.http.Accept-Encoding = "gzip";</div><div> }</div>
<div> elsif (req.http.Accept-Encoding ~ "deflate") {</div><div> set req.http.Accept-Encoding = "deflate";</div><div> }</div><div> else {</div><div> // unknown algorithm</div>
<div> remove req.http.Accept-Encoding;</div><div> }</div><div> }</div></div><div><br></div><div><div> if(req.http.x-preview == "yes" && (req.url ~ ".shtml" || req.url ~ ".html") )</div>
<div> {</div>
<div> hash_data("_preview");</div><div> ##Add device view to hash</div><div> hash_data("_" + req.http.x-preferred-device);</div><div><br></div><div> }else{<br></div><div><br></div>
<div> ##Add device view to hash</div><div> hash_data("_" + req.http.x-device);</div><div> }<br></div><div> return (hash);</div></div><div>}</div><div><br></div><div>#Purge pieces</div><div>vcl_recv {</div>
<div><br></div><div><div> if (req.request == "PURGE") {</div><div> if (!client.ip ~ localaddr) {</div><div> error 405 "Method not allowed";</div><div> }<br>
</div><div> ban("obj.http.x-url ~ " + req.url + " && obj.http.x-host == " + req.http.host + " && obj.http.x-pd ~ .*" );</div><div> std.log("Purge : yes really purge.");</div>
<div> return(lookup);</div><div> }</div></div><div><br></div><div><div>vcl_hit {</div><div> if (req.request == "PURGE") {</div><div> purge;</div><div> error 200 "Purged.";</div>
<div> }</div><div>}</div><div><br></div><div>vcl_miss {</div><div> if (req.request == "PURGE") {</div><div> purge;</div><div> error 200 "Purged.";</div><div>
}</div></div><div><br></div><div> vcl_fetch {</div><div> #setup for banning</div><div> set beresp.http.x-url = req.url;</div><div> set beresp.http.x-host = req.http.host;</div><div> set beresp.http.x-pd = req.http.x-device;</div>
<div><br></div><div> }</div><div><br></div><div><div> vcl_deliver {</div><div> #Clean up banning</div><div> unset resp.http.x-url;</div><div> unset resp.http.x-host;</div><div> unset resp.http.x-pd;</div></div>
<div><br></div><div> }</div>
<div><br></div><div>Thanks in advance,</div><div><br>Richard</div></div>