Implement functions to cache inverse matrix calculation.