Implement the cached matrix functionality (for R Prog, Assignment 2)