Implement cached matrix and inverse solver.