Calculating the inverse of a matrix using cache