Index: includes/path.inc
===================================================================
--- includes/path.inc	(revision 22)
+++ includes/path.inc	(working copy)
@@ -46,8 +46,36 @@
 function drupal_lookup_path($action, $path = '', $path_language = '') {
   global $language;
   // $map is an array with language keys, holding arrays of Drupal paths to alias relations
-  static $map = array(), $no_src = array(), $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 ? $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 ? $cache->data : array();
+    $no_src_expire = $cache ? $cache->expire : time()+(24*60*60);
+  }
+
+  if ($action == 'cache'){
+    if ($map_dirty){
+      cache_set($map_cid, $map, 'cache_path', $map_expire);
+      $map_dirty = FALSE;
+    }
+    if ($no_src_dirty){
+      cache_set($no_src_cid, $no_src, 'cache_path', $no_src_expire);
+      $no_src_dirty = FALSE;
+    }
+  }
+
   $path_language = $path_language ? $path_language : $language->language;
 
   // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
@@ -59,6 +87,10 @@
     $map = array();
     $no_src = array();
     $count = NULL;
+    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') {
@@ -68,6 +100,7 @@
       // Get the most fitting result falling back with alias without language
       $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language));
       $map[$path_language][$path] = $alias;
+      $map_dirty = TRUE;
       return $alias;
     }
     // Check $no_src for this $path in case we've already determined that there
@@ -79,12 +112,14 @@
         // Get the most fitting result falling back with alias without language
         if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) {
           $map[$path_language][$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_language][$path] = TRUE;
+          $no_src_dirty = TRUE;
         }
       }
       return $src;
