The module only purges the current host, in the event that you're using multi-site directory aliasing the aliased pages are not purged.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thewilkybarkid’s picture

Status: Active » Needs review
FileSize
2.15 KB
bibo’s picture

I'd like to add an alternative approach to this problem. I encountered the problem when using cdn-module to offer static files over different domain. In some cases I wanted the static files to be cleared in sync with the rest of the site.

I solved it by actually just ignoring the domain/alias-specific part of the Varnish purge, in a custom drush extension. If I recall correctly, and earlier version of the Varnish module didn't even care about the hostname-part, but flushed just based on the path, or internal url. It was added later to increase hitrates in some scenarios - such as when there are multiple different sites behind the same Varnish instance. It depends on the use case if that is necessary at all.

In my case I just used an internal function of varnish-module, to run this:

  if(function_exists('varnish_purge')){
    //See stolen code from varnish_purge();
    $version = floatval(variable_get('varnish_version', 3.0)); // Default to varnish 3
    $command = $version >= 3 ? "ban" : "purge";
    $pattern = '.*';
    $ret = _varnish_terminal_run(array('$command req.url ~ "$pattern"'));

In essence it would be the same as running the purge through varnish_purge() where "req.http.host ~ $host &&" has been removed (+ the same for ban lurker version).

An option to choose if the purges are limited to the hostname of the active Drupal-installation could be added to the admin settings. Apart from settings form (and documentation of this option), this would only require a few lines in varnish_purge()-function to work globally.

EDIT: replaced some "\"-escaping with ', to avoid problems with drupal.org PHP-filter.

bibo’s picture

I forgot to add that $pattern = '/'; would work just as well as $pattern = '.*'; to flush everything, because "/" matches all paths (with the logic of Varnish).

bibo’s picture

This issue or rather it's solution may be a partial duplicate of an earlier issue, with a slightly more cryptic title: #1847672: VarnishCache::clear() has different behaviour than DrupalDatabaseCache::clear()..

I'm not marking this as a duplicate just yet (if someone agrees though, please change the status). I'm linking to here in a comment from the other issue.

bibo’s picture

JeremyFrench’s picture

Trying to clean these issues into one #2208329: Support Multi domain sites

JeremyFrench’s picture

Status: Needs review » Closed (duplicate)
MiroslavBanov’s picture

Patch #1 works for me, but adding a new patch that keeps the _varnish_get_host() function for backwards compatibility. Other modules may be using it, and it is still being called in some situation from varnish.cache.inc

rkostov’s picture

purge-site-aliases-2185281-9.patch is the same as #8 but compatible with the stable version 7.x-1.4