solution for the cached matrix inversion