Implement cache matrix for assignment 2.