You are here

function expire_cache_derivative in Cache Expiration 6

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

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

Parameters

$paths: Array of current URLs

$node: node object

4 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 in ./expire.module
Implementation of hook_user().

File

./expire.module, line 404
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('path_redirect')) {
      $path_redirects = expire_path_redirect_load(array(
        'redirect' => $path,
      ));
      if (isset($path_redirects)) {
        foreach ($path_redirects as $path_redirect) {
          if (!empty($path_redirect['redirect'])) {
            $expire[] = $path_redirect['redirect'];
          }
        }
      }
    }
  }

  // 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();
  global $base_url;
  if (variable_get('expire_include_base_url', EXPIRE_INCLUDE_BASE_URL)) {
    foreach (expire_get_base_urls($node) as $domain_id) {
      foreach ($domain_id as $base) {
        foreach ($expire as $path) {
          $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);
}