provided the implementation for the cached matrix inversion