Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.354
diff -u -F^f -r1.354 comment.module
--- modules/comment.module	21 Jun 2005 09:45:44 -0000	1.354
+++ modules/comment.module	23 Jun 2005 05:54:14 -0000
@@ -274,6 +274,7 @@ function comment_nodeapi(&$node, $op, $a
     case 'delete':
       db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
       db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
+      cache_clear_all('comment:'. $node->nid);
       break;
 
     case 'update index':
@@ -541,6 +542,9 @@ function comment_post($edit) {
         // Allow modules to respond to the updating of a comment.
         module_invoke_all('comment', 'update', $edit);
 
+        // invalidate cache
+        cache_clear_all('comment:'. $edit['nid']);
+
         // Add an entry to the watchdog log.
         watchdog('content', t('Comment: updated %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
       }
@@ -644,6 +648,9 @@ function comment_post($edit) {
         // Tell the other modules a new comment has been submitted.
         module_invoke_all('comment', 'insert', $edit);
 
+        // invalidate cache
+        cache_clear_all('comment:'. $edit['nid']);
+
         // Add an entry to the watchdog log.
         watchdog('content', t('Comment: added %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
       }
@@ -828,6 +835,12 @@ function comment_render($node, $cid = 0)
       ** substring only.
       */
 
+      $cache_id = 'comment:'. $node->nid;
+      if (!$user->uid && ($cache = cache_get($cache_id))) {
+        return $cache;
+      }
+      $cacheable = TRUE;
+
       if ($order == 1) {
         if ($mode == 1 || $mode == 2) {
           $query .= ' ORDER BY c.timestamp DESC';
@@ -866,6 +879,7 @@ function comment_render($node, $cid = 0)
 
       while ($comment = db_fetch_object($result)) {
         $comment = drupal_unpack($comment);
+        $cacheable = $cacheable && filter_format_allowcache($comment->format);
         $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
         $comment->depth = count(explode('.', $comment->thread)) - 1;
 
@@ -901,6 +915,9 @@ function comment_render($node, $cid = 0)
         $output .= form_hidden('nid', $nid);
         $output .= '</div></form>';
       }
+      if (!$user->uid && $cacheable) {
+        cache_set($cache_id, $output, CACHE_PERMANENT);
+      }
     }
 
     // If enabled, show new comment form.
@@ -1002,6 +1019,9 @@ function comment_save($id, $edit) {
 
   // Allow modules to respond to the updating of a comment.
   module_invoke_all('comment', 'update', $edit);
+
+  // invalidate cache
+  cache_clear_all('comment:'. $edit['nid']);
 }
 
 /**
@@ -1280,6 +1300,9 @@ function comment_moderate() {
             db_query("UPDATE {comments} SET score = '$new_score', users = '%s' WHERE cid = %d", serialize($users), $cid);
 
             module_invoke_all('comment', 'moderate', $cid, $vote);
+
+            // invalidate cache
+            cache_clear_all('comment:'. $comment->nid);
           }
         }
       }
@@ -1613,6 +1636,7 @@ function _comment_delete_thread($comment
   watchdog('content', t('Comment: deleted %subject.', array('%subject' => theme('placeholder', $comment->subject))));
 
   module_invoke_all('comment', 'delete', $comment);
+  cache_clear_all('comment:'. $comment->nid);
 
   // Delete the comment's replies:
   $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid);
