Implementation of caching for matrix inverse calculation