Add caching mechanism for solving the inverse of a matrix