cache magic graph query data to improve performance
Iterated version