You are here

function expire_node in Cache Expiration 7

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

Expires a node from the cache; including related pages.

Expires front page if promoted, taxonomy terms,

Parameters

$node: node object

12 calls to expire_node()
drush_expire_nid in ./expire.drush.inc
Callback for expire-node drush command.
expire_comment_delete in ./expire.module
Implements hook_comment_delete().
expire_comment_insert in ./expire.module
Implements hook_comment_insert().
expire_comment_publish in ./expire.module
Implements hook_comment_publish().
expire_comment_unpublish in ./expire.module
Implements hook_comment_unpublish().

... See full list

File

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

Code

function expire_node($node) {
  $paths = array();

  // Check node object
  if (empty($node->nid)) {
    return FALSE;
  }

  // Expire this node
  $paths['node'] = 'node/' . $node->nid;

  // If promoted to front page, expire front page
  if (variable_get('expire_flush_front', EXPIRE_FLUSH_FRONT) && $node->promote == 1) {
    $paths['front'] = '<front>';
  }

  // Get taxonomy terms and flush
  if (module_exists('taxonomy') && variable_get('expire_flush_node_terms', EXPIRE_FLUSH_NODE_TERMS)) {
    $terms = array();
    $info = field_info_fields();
    foreach (field_info_instances('node', $node->type) as $name => $instance) {
      if ($info[$name]['type'] == 'taxonomy_term_reference') {
        $new_terms = field_get_items('node', $node, $name);
        if (is_array($new_terms)) {
          $terms = array_merge($new_terms, $terms);
        }
        $old_terms = isset($node->original) && !empty($node->original) ? field_get_items('node', $node->original, $name) : array();
        if (is_array($old_terms)) {
          $terms = array_merge($old_terms, $terms);
        }
      }
    }
    foreach ($terms as $term) {
      $paths['term' . $term['tid']] = 'taxonomy/term/' . $term['tid'];
    }
  }

  // Get menu and flush related items in the menu.
  if (module_exists('menu') && variable_get('expire_flush_menu_items', EXPIRE_FLUSH_MENU_ITEMS) != 0) {
    if (!isset($node->menu['menu_name'])) {
      $menu_node = clone $node;
      menu_node_prepare($menu_node);
      $menu = menu_tree_all_data($menu_node->menu['menu_name']);
    }
    else {
      $menu = menu_tree_all_data($node->menu['menu_name']);
    }
    $tempa = NULL;
    $tempb = NULL;
    if (variable_get('expire_flush_menu_items', EXPIRE_FLUSH_MENU_ITEMS) == 1) {
      $links = expire_get_menu_structure($menu, FALSE, 'node/' . $node->nid, NULL, $tempa, $tempb);
    }
    elseif (variable_get('expire_flush_menu_items', EXPIRE_FLUSH_MENU_ITEMS) == 2) {
      $links = expire_get_menu_structure($menu, NULL, NULL, NULL, $tempa, $tempb);
    }
    unset($tempa);
    unset($tempb);
    $paths = array_merge($links, $paths);
  }

  // Get Node References and flush.
  if (variable_get('expire_flush_node_references', EXPIRE_FLUSH_NODE_REFERENCES) && module_exists('node_reference') && module_load_include('inc', 'expire', 'expire.node_reference') != FALSE) {
    $node_references = expire_get_node_references($node);
    $paths = array_merge($node_references, $paths);
  }

  // Flush array of paths
  if (!empty($paths)) {
    $flushed = expire_cache_derivative($paths, $node);
    watchdog('expire', 'Node !nid was flushed resulting in !flushed pages being expired from the cache', array(
      '!nid' => $node->nid,
      '!flushed' => $flushed,
    ));
  }
}