I have a custom module that displays some CCK fields from a node. This will be an example of how to use the boost cache relationship table to expire these custom paths when the node is updated, etc...

Comments

mikeytown2’s picture

Code for views

function boost_views_pre_render(&$view) {
  // return if not a view, page not going to be cached, or if database turned off
  if (is_null($view) || !$GLOBALS['_boost_cache_this'] || BOOST_NO_DATABASE) {
    return;
  }

  // return if view doesn't belong in the set of views to search
  $views = boost_views_get_valid_array();
  $hash = $view->name . ' - ' . $view->current_display;
  if (!array_key_exists($hash, $views)) {
    return;
  }

  foreach ($view->result as $item) {
    // skip if nid is not a number
    if (!is_numeric($item->nid)) {
      continue;
    }

    $node = boost_node_get_basics($item->nid);
    // skip if node type is not set
    if (!isset($node->type)) {
      continue;
    }
    // set data
    $relationship = array(
      'child_page_callback' => 'node',
      'child_page_type' => $node->type,
      'child_page_id' => $item->nid,
    );
    if (BOOST_VERBOSE >= 9) {
      $relationship['debug'] = array(
        'view-name' => $view->name,
        'view-display' => $view->current_display,
        'node-path' => $node->path,
      );
    }
    // send to global
    $GLOBALS['_boost_relationships'][] = $relationship;
  }
}


Code for panels

function boost_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask, $handler) {
  // return if page not going to be cached or if database turned off
  if (!$GLOBALS['_boost_cache_this'] || BOOST_NO_DATABASE) {
    return;
  }

  foreach ($handler->conf['display']->context as $context) {
    if ($context->type == 'node') {
      $node = $context->data;
      // skip if node type is not set
      if (!isset($node->type)) {
        continue;
      }
      // set data
      $relationship = array(
        'child_page_callback' => 'node',
        'child_page_type' => $node->type,
        'child_page_id' => $node->nid,
      );
      if (BOOST_VERBOSE >= 9) {
        $relationship['debug'] = array(
          'panel-task' => $handler->task,
          'panel-subtask' => $handler->subtask,
          'node-path' => $node->path,
        );
      }
      // send to global
      $GLOBALS['_boost_relationships'][] = $relationship;
    }
  }
}
mikeytown2’s picture

Hook menu for this page. How it works is the first number is a node & the second number is the delta of the CCK item.

/**
 * Implementation of hook_menu().
 */
  $items['coupon/%/%'] = array(
    'title' => 'Coupon',
    'description' => 'Display one coupon from the CCK field',
    'page callback' => 'business_profiles_coupon_display',
    'access arguments' => array('access content'),
    'file' => 'business_profiles.coupons.inc',
    'type' => MENU_CALLBACK,
    'page arguments' => array(1, 2),
  );

Page is a custom rendered html page (no theme) that is used in a lightbox popup. What is happening is the node gets updated but the coupon doesn't get flushed from the cache. What I need to do is create a relationship between this custom page and the node.

mikeytown2’s picture

inside business_profiles_coupon_display right at the end of the function I call the newly crated business_profiles_coupon_set_boost_relationship() function.

function business_profiles_coupon_display($nid, $cck_id = 0) {
...
  echo $output;

  // Set boost relationship
  business_profiles_coupon_set_boost_relationship(&$node, $biz_data);
}

/**
 * Set the boost cache relationship.
 *
 * This sets up a relationship between the coupon path and the node object.
 *
 * @param $node
 *   node object
 * @param $coupon_title
 *   title of the coupon; used for debugging purposes. 
 */
function business_profiles_coupon_set_boost_relationship(&$node, $coupon_title) {
  // Return if page not going to be cached or if database turned off.
  if (!$GLOBALS['_boost_cache_this'] || BOOST_NO_DATABASE) {
    return;
  }

  // set data
  $relationship = array(
    'child_page_callback' => 'node',
    'child_page_type' => $node->type,
    'child_page_id' => $node->nid,
  );
  if (BOOST_VERBOSE >= 9) {
    $relationship['debug'] = array(
      'coupon-title' => $coupon_title,
      'node-path' => $node->path,
    );
  }
  // send to global
  $GLOBALS['_boost_relationships'][] = $relationship;
}