Implemented caching to retrieve inverse matrix