Implemented cache functions for matrix inverse