diff --git a/schema_salad/ref_resolver.py b/schema_salad/ref_resolver.py index 1a71e419..15bb835f 100644 --- a/schema_salad/ref_resolver.py +++ b/schema_salad/ref_resolver.py @@ -116,6 +116,9 @@ def fetch_text(self, url): raise ValueError('Unsupported scheme in url: %s' % url) def check_exists(self, url): # type: (unicode) -> bool + if url in self.cache: + return True + split = urlparse.urlsplit(url) scheme, path = split.scheme, split.path diff --git a/schema_salad/tests/test_fetch.py b/schema_salad/tests/test_fetch.py index 9b615086..7c74a64d 100644 --- a/schema_salad/tests/test_fetch.py +++ b/schema_salad/tests/test_fetch.py @@ -35,3 +35,11 @@ def check_exists(self, url): # type: (unicode) -> bool with self.assertRaises(RuntimeError): loader.resolve_ref("bar.txt") self.assertFalse(loader.check_exists("bar.txt")) + + def test_cache(self): + loader = schema_salad.ref_resolver.Loader({}) + foo = "file://%s/foo.txt" % os.getcwd() + loader.cache.update({foo: "hello: foo"}) + print loader.cache + self.assertEqual({"hello": "foo"}, loader.resolve_ref("foo.txt")[0]) + self.assertTrue(loader.check_exists(foo))