--- includes/path.inc.orig	2008-08-08 09:58:41.553219064 -0400
+++ includes/path.inc	2008-08-08 10:25:32.353732994 -0400
@@ -41,8 +41,35 @@
  */
 function drupal_lookup_path($action, $path = '') {
   // $map keys are Drupal paths and the values are the corresponding aliases
-  static $map = array(), $no_src = array();
-  static $count;
+
+  global $base_root;
+  static $map, $no_src, $count, $map_dirty, $no_src_dirty;
+
+  $map_cid = 'map_'. $base_root . request_uri();
+  $no_src_cid = 'no_src_'. $base_root . request_uri();
+
+  if (!isset($map)){
+    $cache = cache_get($map_cid, 'cache_path');
+    $map = $cache ? unserialize($cache->data) : array();
+    $map_expire = $cache ? $cache->expire : time()+(24*60*60);
+  }
+
+  if (!isset($no_src)){
+    $cache = cache_get($no_src_cid, 'cache_path');
+    $no_src = $cache ? unserialize($cache->data) : array();
+    $no_src_expire = $cache ? $cache->expire : time()+(24*60*60);
+  }
+
+  if ($action == 'cache'){
+    if ($map_dirty){
+      cache_set($map_cid, 'cache_path', serialize($map), $map_expire);
+      $map_dirty = FALSE;
+    }
+    if ($no_src_dirty){
+      cache_set($no_src_cid, 'cache_path', serialize($no_src), $no_src_expire);
+      $no_src_dirty = FALSE;
+    }
+  }
 
   // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
   if (!isset($count)) {
@@ -52,6 +79,10 @@
   if ($action == 'wipe') {
     $map = array();
     $no_src = array();
+    cache_clear_all($map_cid, 'cache_path');
+    cache_clear_all($no_src_cid, 'cache_path');
+    $map_dirty = TRUE;
+    $no_src_dirty = TRUE;
   }
   elseif ($count > 0 && $path != '') {
     if ($action == 'alias') {
@@ -60,6 +91,7 @@
       }
       $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
       $map[$path] = $alias;
+      $map_dirty = TRUE;
       return $alias;
     }
     // Check $no_src for this $path in case we've already determined that there
@@ -69,12 +101,14 @@
       if (!$src = array_search($path, $map)) {
         if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
           $map[$src] = $path;
+          $map_dirty = TRUE;
         }
         else {
           // We can't record anything into $map because we do not have a valid
           // index and there is no need because we have not learned anything
           // about any Drupal path. Thus cache to $no_src.
           $no_src[$path] = TRUE;
+          $no_src_dirty = TRUE;
         }
       }
       return $src;
