Caching implementation of matrix inverse