Implements caching of matrix inverse