Implemented the matrix inverse functionality with caching capabilities.