Inverse matrix with caching