Cached matrix inversion