Speed up the lineage computation by doing some caching.