--- /home/jowouters/cvs.drupal.org/contrib-5.x-1.x/modules/cacherouter/engines/file.php	2008-04-08 00:18:23.000000000 +0200
+++ ./engines/file.php	2008-07-28 23:15:29.000000000 +0200
@@ -73,7 +73,7 @@ class fileCache extends Cache {
     return FALSE;
   }
   
-  function set($key, $value, $expire = CACHE_PERMENANT, $headers = NULL) {
+  function set($key, $value, $expire = CACHE_PERMANENT, $headers = NULL) {
     static $subdirectories;
 
     if (variable_get('page_cache_fastpath', 0)) {
@@ -105,12 +105,30 @@ class fileCache extends Cache {
   }
   
   function delete($key) {
-    $file = $this->key($key);
-    if ($fp = fopen($file, 'w')) {
-      // only delete the cache file once we obtain an exclusive lock to prevent
-      // deleting a cache file that is currently being read.
-      if (flock($fp, LOCK_EX)) {
-        unlink($file);
+    // when using wildcard: $key is part-of-key + '*'
+    if (strrpos($key, '*')) {
+      $look_for = explode('*', $key);
+      $fspath = $this->fspath;
+      // Filename: abcdef12345verylongmd5code--content:123456:987654
+      $files = file_scan_directory($fspath, ".--$look_for[0].", array('.', '..', 'CVS'));
+      foreach ($files as $file) {
+        if ($fp = fopen($file, 'w')) {
+          // only delete the cache file once we obtain an exclusive lock to prevent
+          // deleting a cache file that is currently being read.
+          if (flock($fp, LOCK_EX)) {
+            unlink($file);
+          }
+        }
+      }      
+    }
+    else {
+      $file = $this->key($key);
+      if ($fp = fopen($file, 'w')) {
+        // only delete the cache file once we obtain an exclusive lock to prevent
+        // deleting a cache file that is currently being read.
+        if (flock($fp, LOCK_EX)) {
+          unlink($file);
+        }
       }
     }
   }
@@ -139,10 +157,12 @@ class fileCache extends Cache {
     $table = $this->name;
     $fspath = $this->fspath;
     $hash = md5($key);
+    // TODO make sure we always get valid filenames in the appendix
+    $appendix = str_replace(array('/'), array('-'), $key);
     
     $this->create_directory($fspath, $hash{0});
     
-    return  "$fspath/$table/". $hash{0}. '/'. $hash;
+    return  "$fspath/$table/". $hash{0}. '/'. $hash. '--'. $appendix;
   }
   
   /**
@@ -189,4 +209,4 @@ class fileCache extends Cache {
       }
     }
   }
-}
\ No newline at end of file
+}
