Improve control flow when updating the global cache and generating a prompt.