implement cache of matrix inversion functions