add caching mechanism to speed up batch upgrading and also fix a pretty bad bug