Complete code for Simulation Caching, not tested.

Test Caching