diff --git a/src/reaction_generator.py b/src/reaction_generator.py index c3e8e78..f04ed9f 100755 --- a/src/reaction_generator.py +++ b/src/reaction_generator.py @@ -787,6 +787,15 @@ def prime_entity_caches(reaction_connections: pd.DataFrame) -> None: # would make the network depend on build order (deltasignal specs/065). from src.variant_emission import _sig_cache _sig_cache.clear() + # So are the structure memos built from those getters (specs/065 + # amendment 1); caches filled by their own direct query hold database + # truth and are kept. + import src.logic_network_generator as lng + for c in (lng._variant_leafsets_cache, lng._matching_leaves_cache, + lng._handoff_leaf_cache, lng._sets_chosen_cache): + c.clear() + from src import variant_keys + variant_keys.reset_caches() clear_prefetch_cache() reaction_ids = reaction_ids_from_connections(reaction_connections) if not reaction_ids: diff --git a/tests/test_variant_emission.py b/tests/test_variant_emission.py index a79f869..38bf8bb 100644 --- a/tests/test_variant_emission.py +++ b/tests/test_variant_emission.py @@ -251,3 +251,19 @@ def test_priming_a_pathway_clears_set_member_signatures(monkeypatch): ve._sig_cache[("M1", True)] = ("stale",) rg.prime_entity_caches(None) assert ve._sig_cache == {} + + +def test_priming_a_pathway_clears_derived_structure_caches(monkeypatch): + # specs/065 amendment 1: every memo computed from the prefetch-limited + # getters is per pathway. + import src.reaction_generator as rg + import src.logic_network_generator as lng + monkeypatch.setattr(rg, "reaction_ids_from_connections", lambda rc: ["R1"]) + monkeypatch.setattr(rg, "prefetch_entity_data", lambda ids: None) + caches = (lng._variant_leafsets_cache, lng._matching_leaves_cache, + lng._handoff_leaf_cache, lng._sets_chosen_cache, + vk._memo, vk._variants_cache, vk._struct) + for c in caches: + c["stale"] = None + rg.prime_entity_caches(None) + assert all("stale" not in c for c in caches)