Cached inversion of a matrix