You are here

function expire_comment in Cache Expiration 6

Implementation of hook_comment().

Acts on comment modification.

File

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

Code

function expire_comment($comment, $op) {

  // Convert array to object
  if (is_array($comment)) {
    $comment = (object) $comment;
  }

  // Return if no node id is attached to the comment.
  if (empty($comment->nid)) {
    return;
  }

  // Select which comment opperations require a cache flush.
  $cases = array(
    'insert',
    'update',
    'publish',
    'unpublish',
    'delete',
  );

  // Expire the relevant node page from the static page cache to prevent serving stale content.
  if (in_array($op, $cases)) {
    $node = node_load($comment->nid);
    if ($node) {
      expire_node($node);
    }
  }
}