code: def _cached_clone(url, rev):
      """Clone an external git repo to a temporary directory.
  
      Returns the path to a local temporary directory with the specified
      revision checked out.
      """
      from shutil import copytree
  
      # even if we have already cloned this repo, we may need to
      # fetch/fast-forward to get specified rev
      clone_path, shallow = _clone_default_branch(url, rev)
  
      if url in CLONES:
          return CLONES[url][0]
  
      # Copy to a new dir to keep the clone clean
      repo_path = tempfile.mkdtemp("dvc-erepo")
      logger.debug("erepo: making a copy of %s clone", url)
      copytree(clone_path, repo_path)
  
      CLONES[url] = (repo_path, shallow)
      return repo_path
  
imports: import os
  import tempfile
  import threading
  from typing import TYPE_CHECKING, Dict, Optional, Tuple
  from funcy import retry, wrap_with
  from dvc.exceptions import NotDvcRepoError
  from dvc.log import logger
  from dvc.repo import Repo
  from dvc.scm import CloneError, map_scm_exception
  from dvc.utils import relpath
label_desc: Use image node_id 7 for calling a global function with example usage: _cached_clone(url, rev) and returns: repo_path, CLONES