cached matrix inverse implementation