adding the core logic for cached inversion of a matrix