=== modified file 'includes/common.inc'
--- includes/common.inc	2006-11-29 06:03:56 +0000
+++ includes/common.inc	2006-11-29 12:59:54 +0000
@@ -1249,6 +1249,7 @@ function drupal_page_footer() {
   if (variable_get('cache', 0)) {
     page_set_cache();
   }
+  drupal_lookup_path('cache');
 
   module_invoke_all('exit');
 }

=== modified file 'includes/path.inc'
--- includes/path.inc	2006-11-26 01:55:37 +0000
+++ includes/path.inc	2006-11-29 17:32:49 +0000
@@ -32,6 +32,7 @@ function drupal_init_path() {
  *   - wipe: delete the alias cache.
  *   - alias: return an alias for a given Drupal system path (if one exists).
  *   - source: return the Drupal system URL for a path alias (if one exists).
+ *   - cache: (internal use only) save the maps into the cache_path table.
  * @param $path
  *   The path to investigate for corresponding aliases or system URLs.
  *
@@ -41,46 +42,74 @@ function drupal_init_path() {
  */
 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 = NULL;
+  static
+    $map, $no_src,
+    $map_dirty = FALSE, $no_src_dirty = FALSE,
+    $count = NULL;
+  global $base_root;
+
 
   // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
   if ($count === NULL) {
     $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));
   }
 
-  if ($action == 'wipe') {
-    $map = array();
-    $no_src = array();
-  }
-  elseif ($count > 0 && $path != '') {
-    if ($action == 'alias') {
-      if (isset($map[$path]) || array_key_exists($path, $map)) {
-        return $map[$path];
-      }
-      $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
-      $map[$path] = $alias;
-      return $alias;
-    }
-    // Check $no_src for this $path in case we've already determined that there
-    // isn't a path that has this alias
-    elseif ($action == 'source' && !isset($no_src[$path])) {
-      // Look for the value $path within the cached $map
-      if (!$src = array_search($path, $map)) {
-        if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
-          $map[$src] = $path;
+  if (!isset($map)) {
+    $cache = cache_get('map_'. $base_root . request_uri(), 'cache_path');
+    $cache = unserialize($cache->data);
+    $map = $cache ? $cache : array();
+    $cache = cache_get('no_src_'. $base_root . request_uri(), 'cache_path');
+    $cache = unserialize($cache->data);
+    $no_src = $cache ? $cache : array();
+  }
+  switch ($action) {
+    case 'alias':
+      if ($count > 0 && $path) {
+        if (isset($map[$path])) {
+          return $map[$path];
         }
-        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;
+        if (!$alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path))) {
+          $alias = FALSE;
+        }
+        $map[$path] = $alias;
+        $map_dirty = TRUE;
+        return $alias;
+      }
+      break;
+    case 'source':
+      // Check $no_src for this $path in case we've already determined that there
+      // isn't a path that has this alias
+      if ($count > 0 && $path && !isset($no_src[$path])) {
+        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 FALSE;
+          }
         }
+        return $src;
       }
-      return $src;
-    }
+      break;
+    case 'wipe':
+      $map = array();
+      $no_src = array();
+      break;
+    case 'cache':
+      if ($map_dirty) {
+        cache_set('map_'. $base_root . request_uri(), 'cache_path', serialize($map));
+      }
+      if ($no_src_dirty) {
+        cache_set('no_src_' . $base_root . request_uri(), 'cache_path', serialize($no_src));
+      }
+      break;
   }
-
   return FALSE;
 }
 

