Implementation of caching matrix inverse