Fix port caching with dynamic ports