Index: Cache.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cacherouter/Cache.php,v
retrieving revision 1.1.2.16
diff -u -p -r1.1.2.16 Cache.php
--- Cache.php	4 Feb 2010 16:11:42 -0000	1.1.2.16
+++ Cache.php	21 Jul 2010 08:37:55 -0000
@@ -108,9 +108,17 @@ class CacheRouterEngine {
    *   Returns TRUE on success, FALSE on failure
    */
   function lock() {
-    $this->lock_fp = fopen($this->lock, "w");
-    flock($this->lock_fp, LOCK_EX);
-    return TRUE;
+    // Use the new D6.16 locking functionality if its available:
+    if (function_exists('lock_acquire')) {
+      // $this->lock could be arbitrarily long, so we'll hash it:
+      return lock_acquire(md5($this->lock));
+    }
+    // Otherwise fallback to using files:
+    else {
+      $this->lock_fp = fopen($this->lock, "w");
+      flock($this->lock_fp, LOCK_EX);
+      return TRUE;
+    }
   }
 
   /**
@@ -122,6 +130,14 @@ class CacheRouterEngine {
    *   Returns TRUE on success, FALSE on failure
    */
   function unlock() {
-    unlink($this->lock);
+    // Use the new D6.16 locking functionality if its available:
+    if (function_exists('lock_release')) {
+      lock_release(md5($this->lock));
+    }
+    // Otherwise fallback to using files:
+    else {
+      unlink($this->lock);
+    }
+
   }
 }
