Caching and calculation of inverse matrix