Is it possible to purge all files underneath a specific directory using Varnish? How could you go about completing this in a PHP script?
For example, if a URL includes the path /product/a-specific-product/
, is it also possible to purge files such as /product/a-specific-product/a-sub-page/
?
I have the following functions that are used to purge a specific URL in Varnish 3 (part of class VarnishPurger()
:
public function executePurge()
{
$purgeUrls = array_unique($this->purgeUrls);
foreach($purgeUrls as $url)
{
$this->purgeUrl($url);
}
if (!empty($purgeUrls))
{
$this->purgeUrl(home_url());
}
}
protected function purgeUrl($url)
{
$c = curl_init($url);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'PURGE');
curl_exec($c);
curl_close($c);
}