I got a PHP error calling varnish_expire_cache() from my hook_nodeapi function because varnish_expire_cache() ends with a break, instead of a return. I have attached a patch with the fix.

Here is the function from which I was calling it. I think I am doing this correctly. At least, my testing so far has indicated that URL's are being cleared out of the cache:

function um_common_nodeapi(&$node, $op, $a3, $a4) {
  switch ($op) {
    case 'alter':
       // snip irrelevant code
    break;
    case 'insert':
    case 'update':
	if (module_exists('varnish')) {
          $urls = varnish_get_active_urls($node);
          varnish_expire_cache($urls);
	}
     break;
  }
}
CommentFileSizeAuthor
#1 fix-varnish-expire-cache.patch519 bytesEvanDonovan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EvanDonovan’s picture

Status: Active » Needs review
FileSize
519 bytes

Sorry, forgot to attach the patch.

EvanDonovan’s picture

I noticed that the varnish_get_active_urls() function has been removed in preparation for people to use the experimental Expire.module. So I've created my own, minimalist version of it in my custom module.

I will probably be testing the Expire.module at some point soon, but will have to see how it fits in with the other priorities at my organization. Anyway, at least this seems to meet my basic needs, now that I've fixed the error in the varnish_expire_cache() function.

function varnish_get_active_urls($node) { 	 
	   $urls = array(); 	 
	   $urls[] = 'node/'. $node->nid;
		 // Have removed extra logic - just keep this as simple as possible.
	   foreach($urls as $url) { 	 
	     $alias = drupal_get_path_alias($url);
	     if ($alias != $url) { 	 
	       $urls[] = $alias; 	 
	     } 	 
	   } 	 
	   return $urls; 	 
}
carlos8f’s picture

I came across the same bug. I don't think hook_expire_caches() needs to return anything though, so the break; just needs to be removed.

EvanDonovan’s picture

Title: varnish_expire_cache() function should end with a return, not break » varnish_expire_cache() function should not have a break at end
Status: Needs review » Needs work

You're right, I think :)

joshk’s picture

Status: Needs work » Fixed

Fixed in cvs.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.