You are here

function expire_cache_derivative in Cache Expiration 7

Same name and namespace in other branches
  1. 6 expire.module \expire_cache_derivative()

Finds all possible paths/redirects/aliases given the root path.

Parameters

$paths: Array of current URLs

$node: node object

6 calls to expire_cache_derivative()
drush_expire_path in ./expire.drush.inc
Callback for expire-path drush command.
expire_node in ./expire.module
Expires a node from the cache; including related pages.
expire_rules_action_flush_url in ./expire.rules.inc
Expire a URL from the page cache.
expire_user_delete in ./expire.module
Implements hook_user_delete
expire_user_insert in ./expire.module
Implements hook_user_insert

... See full list

File

./expire.module, line 395
Provides logic for page cache expiration

Code

function expire_cache_derivative($paths, &$node = NULL) {
  global $base_path;
  $expire = array();
  if (empty($paths)) {
    return FALSE;
  }
  $site_frontpage = variable_get('site_frontpage', 'node');
  foreach ($paths as $path) {

    // Special front page handling
    if ($path == $site_frontpage || $path == '' || $path == '<front>') {
      $expire[] = '';
      $expire[] = 'rss.xml';
      $expire[] = $site_frontpage;
    }

    // Add given path
    if ($path != '<front>') {
      $expire[] = $path;
    }

    // Path alias
    $path_alias = url($path, array(
      'absolute' => FALSE,
    ));

    // Remove the base path
    $expire[] = substr($path_alias, strlen($base_path));

    // Path redirects
    if (module_exists('redirect')) {
      $redirects = redirect_load_multiple(array(), array(
        'redirect' => $path,
      ));
      if (isset($redirects) && !empty($redirects)) {
        foreach ($redirects as $redirect) {
          if (!empty($redirect->source)) {
            $expire[] = $redirect->source;
          }
        }
      }
    }
  }

  // Allow other modules to modify the list prior to expiring
  drupal_alter('expire_cache', $expire, $node, $paths);

  // Expire cached files
  if (empty($expire)) {
    return FALSE;
  }
  $expire = array_unique($expire);

  // Add on the url to these paths
  $urls = array();
  if (variable_get('expire_include_base_url', EXPIRE_INCLUDE_BASE_URL)) {
    $base_urls[] = url('', array(
      'absolute' => TRUE,
    ));
    if (module_exists('domain') && module_load_include('inc', 'expire', 'expire.domain') != FALSE) {
      $base_urls = array_merge($base_urls, expire_get_base_urls($node));
    }
    foreach ($expire as $path) {
      foreach ($base_urls as $base) {

        // If domain access is enabled the $base_urls is an array with configured subdomains
        if (is_array($base)) {
          foreach ($base as $subdomain) {
            $urls[] = $subdomain . $path;
          }
        }
        else {
          $base = rtrim($base, '/') . '/';
          $urls[] = $base . $path;
        }
      }
    }
  }
  else {
    $urls = $expire;
  }

  // hook_expire_cache
  $modules = module_implements('expire_cache');
  foreach ($modules as $module) {
    module_invoke($module, 'expire_cache', $urls);
  }
  watchdog('expire', 'Input: !paths <br /> Output: !urls <br /> Modules Using hook_expire_cache(): !modules', array(
    '!paths' => expire_print_r($paths),
    '!urls' => expire_print_r($urls),
    '!modules' => expire_print_r($modules),
  ));
  return count($urls);
}