You are here

function varnish_expire_cache in Varnish 7

Same name and namespace in other branches
  1. 6 varnish.module \varnish_expire_cache()

Implements hook_expire_cache().

Takes an array from expire.module and issue purges. You may also safely call this function directly with an array of local urls to purge.

Parameters

$paths: Associative array of paths to be purged, where both keys and values are paths.

$wildcards: (Optional) Array of wildcards to be applied, as an associative array where paths are keys and booleans indicating if the path should have a wildcard at the end are values.

2 calls to varnish_expire_cache()
VarnishCache::clear in ./varnish.cache.inc
Expires data from the cache.
varnish_drush_purge in ./varnish.drush.inc
Callback for varnish-purge drush command.

File

./varnish.module, line 108
Common functions used for the module.

Code

function varnish_expire_cache($paths, $wildcards = array()) {
  if (count($wildcards)) {
    foreach ($wildcards as $path => $wildcard) {
      if ($wildcard) {
        $paths[$path] .= '([/?].*)?';
      }
    }
  }
  if (module_exists('expire') && variable_get('expire_include_base_url', constant('EXPIRE_INCLUDE_BASE_URL'))) {

    // Sort the URLs by domain and batch by domain.
    $host_buckets = array();
    foreach ($paths as $url) {
      $parts = parse_url($url);

      // Strip base path from the path because it will be added later.
      $path = substr($parts['path'], strlen(base_path()));
      $host_buckets[$parts['host']][] = $path . (!empty($parts['query']) ? '?' . $parts['query'] : '');
    }
    foreach ($host_buckets as $host => $purges) {
      varnish_purge_paths($host, $purges);
    }
  }
  else {
    $host = _varnish_get_host();
    varnish_purge_paths($host, $paths);
  }
}