 +        if res is None or childpath is None: return None
 +        
 +        url = joinURL(self.urlForResource(res), childpath)
-+        try:
-+            return succeed(self._urlsByResource[url])
-+        except KeyError:
-+            pass
++
++        cached = self._urlsByResource.get(url, None)
++        if cached is not None:
++            return succeed(cached)
 +
 +        segment = unquote(childpath)
 +

     def _rememberURLForResource(self, url, resource):
         """
         Remember the URL of visited resources.
@@ -385,8 +404,14 @@
             The contained response will have a status code of
             L{responsecode.BAD_REQUEST}.
         """

+        if url is None:
+            return None
 
+        cached = self._urlsByResource.get(url, None)
+        if cached is not None:
+            return succeed(cached)
+
         #
         # Parse the URL
         #
@@ -414,11 +435,56 @@
         def notFound(f):
             f.trap(http.HTTPError)
             if f.response.code != responsecode.NOT_FOUND:
