Clearing page cache in drupal after Adding Comments on contents

Using Page cache is normaly helpful for providing better performances on server. And serving cached pages from database helps the

servers to work faster.

in drupal When caching is turned on the HTML output of a page is stored in the cache_page table, so one query is enough to retrieve the HTML output for display instead of hundreds of queries on pages with many blocks, links, etc.

For logged in users pages are not retrieved from the cache but are newly generated each time they request a page. If logged in users post a comment for example they see it immediately after they hit the submit button, wheres non-logged users have to wait until the minimum cache lifetime of the page has expired.

In hook_comment you can use the function for clearing cache of page:-

cache_clear_all($url, 'cache_page'); //where $url is url of page

 

if ($nid) {
   
// retrieve the absolute url for the node
   
$url = url('node/'. $nid, NULL, NULL, TRUE);
   
// delete cache entries for that url
   
cache_clear_all($url, 'cache_page');
  }
function custom_comment($a1, $op) {
  switch (
$op) {
    case
'insert':
    case
'update':
     
$nid = $a1['nid'];
      break;
    case
'unpublish':
    case
'delete':
     
$nid = $a1->nid;
      break;
  }
  if (
$nid) {
   
// retrieve the absolute url for the node
   
$url = url('node/'. $nid, NULL, NULL, TRUE);
   
// delete cache entries for that url
   
cache_clear_all($url, 'cache_page');
  }
}