Added code for matrix caching for Assignment 2