Add implementation of caching of matrix inversion.