Implement caching of matrix inverse