Solve matrix inversion with caching