docstr: Construct a handle for the specified deployment.
  
  Args:
      deployment_name: Deployment name.
      app_name: Application name.
      missing_ok: If true, then Serve won't check the deployment
          is registered. False by default.
      sync: If true, then Serve will return a ServeHandle that
          works everywhere. Otherwise, Serve will return a ServeHandle
          that's only usable in asyncio loop.
  
  Returns:
      RayServeHandle
docstr_tok: ["Construct","a","handle","for","the","specified","deployment",".","Args",":","deployment_name",":","Deployment","name",".","app_name",":","Application","name",".","missing_ok",":","If","true",",","then","Serve","wo","n't","check","the","deployment","is","registered",".","False","by","default",".","sync",":","If","true",",","then","Serve","will","return","a","ServeHandle","that","works","everywhere",".","Otherwise",",","Serve","will","return","a","ServeHandle","that","'s","only","usable","in","asyncio","loop",".","Returns",":","RayServeHandle"]
code: def get_handle(
      self,
      deployment_name: str,
      app_name: Optional[str] = "default",
      missing_ok: Optional[bool] = False,
      sync: bool = True,
      use_new_handle_api: bool = RAY_SERVE_ENABLE_NEW_HANDLE_API,
  ) -> Union[DeploymentHandle, RayServeHandle, RayServeSyncHandle]:
      """Construct a handle for the specified deployment.
  
      Args:
          deployment_name: Deployment name.
          app_name: Application name.
          missing_ok: If true, then Serve won't check the deployment
              is registered. False by default.
          sync: If true, then Serve will return a ServeHandle that
              works everywhere. Otherwise, Serve will return a ServeHandle
              that's only usable in asyncio loop.
  
      Returns:
          RayServeHandle
      """
      cache_key = (deployment_name, app_name, missing_ok, sync)
      if cache_key in self.handle_cache:
          return self.handle_cache[cache_key]
  
      all_deployments = ray.get(
          self._controller.list_deployment_ids.remote()
      )
      if (
          not missing_ok
          and DeploymentID(deployment_name, app_name)
          not in all_deployments
      ):
          raise KeyError(
              f"Deployment '{deployment_name}' in application '{app_name}' does not "
              "exist."
          )
  
      if use_new_handle_api:
          handle = DeploymentHandle(
              deployment_name,
              app_name,
              # Only used when users convert this back to deprecated handle types.
              sync=sync,
          )
      elif sync:
          handle = RayServeSyncHandle(
              deployment_name,
              app_name,
              # Only used when users convert this back to deprecated handle types.
              sync=sync,
          )
      else:
          handle = RayServeHandle(
              deployment_name,
              app_name,
              # Only used when users convert this back to deprecated handle types.
              sync=sync,
          )
  
      self.handle_cache[cache_key] = handle
      if cache_key in self._evicted_handle_keys:
          logger.warning(
              "You just got a ServeHandle that was evicted from internal "
              "cache. This means you are getting too many ServeHandles in "
              "the same process, this will bring down Serve's performance. "
              "Please post a github issue at "
              "https://github.com/ray-project/ray/issues to let the Serve "
              "team to find workaround for your use case."
          )
  
      if len(self.handle_cache) > MAX_CACHED_HANDLES:
          # Perform random eviction to keep the handle cache from growing
          # infinitely. We used use WeakValueDictionary but hit
          # https://github.com/ray-project/ray/issues/18980.
          evict_key = random.choice(list(self.handle_cache.keys()))
          self._evicted_handle_keys.add(evict_key)
          self.handle_cache.pop(evict_key)
  
      return handle
  
imports: import logging
  import random
  import time
  from functools import wraps
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  import ray
  from ray.actor import ActorHandle
  from ray.serve._private.common import ApplicationStatus, DeploymentID, DeploymentStatus, DeploymentStatusInfo, MultiplexedReplicaInfo, StatusOverview
  from ray.serve._private.config import DeploymentConfig, ReplicaConfig
  from ray.serve._private.constants import CLIENT_CHECK_CREATION_POLLING_INTERVAL_S, CLIENT_POLLING_INTERVAL_S, MAX_CACHED_HANDLES, RAY_SERVE_ENABLE_NEW_HANDLE_API, SERVE_DEFAULT_APP_NAME
  from ray.serve._private.controller import ServeController
  from ray.serve._private.deploy_utils import get_deploy_args
  from ray.serve._private.deployment_info import DeploymentInfo
  from ray.serve.config import HTTPOptions
  from ray.serve.exceptions import RayServeException
  from ray.serve.generated.serve_pb2 import DeploymentArgs, DeploymentRoute, DeploymentRouteList
  from ray.serve.generated.serve_pb2 import DeploymentStatusInfo
  from ray.serve.generated.serve_pb2 import StatusOverview
  from ray.serve.handle import DeploymentHandle, RayServeHandle, RayServeSyncHandle
  from ray.serve.schema import LoggingConfig, ServeApplicationSchema, ServeDeploySchema
label_desc: Use image node_id 24 for calling the ServeControllerClient obj's underlying member method code with example usage: obj.get_handle(deployment_name, app_name, missing_ok, sync, use_new_handle_api) and returns: handle, self