-
Notifications
You must be signed in to change notification settings - Fork 61
Description
The schemas opened via asdf.schema.load_schema
are cached using:
Lines 462 to 488 in a346a6b
@lru_cache | |
def _load_schema_cached(url, resolver, resolve_references): | |
loader = _make_schema_loader(resolver) | |
schema, url = loader(url) | |
if resolve_references: | |
def resolve_refs(node, json_id): | |
if json_id is None: | |
json_id = url | |
if isinstance(node, dict) and "$ref" in node: | |
suburl_base, suburl_fragment = _safe_resolve(resolver, json_id, node["$ref"]) | |
if suburl_base == url or suburl_base == schema.get("id"): | |
# This is a local ref, which we'll resolve in both cases. | |
subschema = schema | |
else: | |
subschema = load_schema(suburl_base, resolver, True) | |
return reference.resolve_fragment(subschema, suburl_fragment) | |
return node | |
schema = treeutil.walk_and_modify(schema, resolve_refs) | |
return schema |
This can present a problem when working with schema resources that are not included in asdf under normal operations. During testing I want to be able to load those schemas, but later I want loading those schemas to fail. This is because otherwise I end up with a situation where the order that tests are run influences whether or not tests pass or fail.
Thus it would be useful to have a mechanism to clear this cache without having to access it through a private API with asdf.schema._load_schema_cached.cache_clear()
.
Alternately, we may want to make the schema cache tied to the current AsdfConfig
so things like what I am trying to do can be done within a special AsdfConfig
context.