Cached implementation of inverse of matrix