Implementing caching of inverse matrix