code: def get_from_cache(url: str, cache_dir: Path = None) -> Path:
      r"""
      尝试在 ``cache_dir``中寻找 ``url`` 定义的资源，如果没有找到，则从 ``url`` 下载并将结果放在 ``cache_dir`` 下，
      缓存的名称由 ``url`` 的结果推断而来。会将下载的文件解压，将解压后的文件全部放在 ``cache_dir`` 文件夹中。
  
      如果从 ``url``中下载的资源解压后有多个文件，则返回目录的路径；如果只有一个资源文件，则返回具体的路径。
  
      :param url: 资源的 url
      :param cache_dir: cache 目录
      :return: 路径
      """
      cache_dir.mkdir(parents=True, exist_ok=True)
  
      filename = re.sub(r".+/", "", url)
      dir_name, suffix = split_filename_suffix(filename)
  
      # 寻找与它名字匹配的内容, 而不关心后缀
      match_dir_name = match_file(dir_name, cache_dir)
      if match_dir_name:
          dir_name = match_dir_name
      cache_path = cache_dir / dir_name
  
      # get cache path to put the file
      if cache_path.exists():
          return get_filepath(cache_path)
  
      # make HEAD request to check ETag TODO ETag可以用来判断资源是否已经更新了，之后需要加上
      # response = requests.head(url, headers={"User-Agent": "fastNLP"})
      # if response.status_code != 200:
      #     raise IOError(
      #         f"HEAD request failed for url {url} with status code {response.status_code}."
      #     )
  
      # add ETag to filename if it exists
      # etag = response.headers.get("ETag")
  
      if not cache_path.exists():
          # Download to temporary file, then copy to cache dir once finished.
          # Otherwise you get corrupt cache entries if the download gets interrupted.
          # GET file object
          req = requests.get(
              url, stream=True, headers={"User-Agent": "fastNLP"}
          )
          if req.status_code == 200:
              success = False
              fd, temp_filename = tempfile.mkstemp()
              uncompress_temp_dir = None
              try:
                  content_length = req.headers.get("Content-Length")
                  total = (
                      int(content_length)
                      if content_length is not None
                      else None
                  )
                  # progress = tqdm(unit="B", total=total, unit_scale=1)
                  progress = Progress(
                      BarColumn(),
                      TimeElapsedColumn(),
                      "/",
                      TimeRemainingColumn(),
                      DownloadColumn(),
                  )
                  task = progress.add_task(
                      total=total, description="download"
                  )
                  progress.start()
                  logger.info(
                      "%s not found in cache, downloading to %s"
                      % (url, temp_filename)
                  )
  
                  with open(temp_filename, "wb") as temp_file:
                      for chunk in req.iter_content(
                          chunk_size=1024 * 16
                      ):
                          if chunk:  # filter out keep-alive new chunks
                              progress.update(task, advance=len(chunk))
                              temp_file.write(chunk)
                  progress.stop()
                  progress.remove_task(task)
                  logger.info(f"Finish download from {url}")
  
                  # 开始解压
                  if suffix in (".zip", ".tar.gz", ".gz"):
                      uncompress_temp_dir = tempfile.mkdtemp()
                      logger.info(
                          f"Start to uncompress file to {uncompress_temp_dir}"
                      )
                      if suffix == ".zip":
                          unzip_file(
                              Path(temp_filename),
                              Path(uncompress_temp_dir),
                          )
                      elif suffix == ".gz":
                          ungzip_file(
                              temp_filename,
                              uncompress_temp_dir,
                              dir_name,
                          )
                      else:
                          untar_gz_file(
                              Path(temp_filename),
                              Path(uncompress_temp_dir),
                          )
                      filenames = os.listdir(uncompress_temp_dir)
                      if len(filenames) == 1:
                          if os.path.isdir(
                              os.path.join(
                                  uncompress_temp_dir, filenames[0]
                              )
                          ):
                              uncompress_temp_dir = os.path.join(
                                  uncompress_temp_dir, filenames[0]
                              )
  
                      cache_path.mkdir(parents=True, exist_ok=True)
                      logger.info("Finish un-compressing file.")
                  else:
                      uncompress_temp_dir = temp_filename
                      cache_path = str(cache_path) + suffix
  
                  # 复制到指定的位置
                  logger.info(f"Copy file to {cache_path}")
                  if os.path.isdir(uncompress_temp_dir):
                      for filename in os.listdir(uncompress_temp_dir):
                          if os.path.isdir(
                              os.path.join(
                                  uncompress_temp_dir, filename
                              )
                          ):
                              shutil.copytree(
                                  os.path.join(
                                      uncompress_temp_dir, filename
                                  ),
                                  cache_path / filename,
                              )
                          else:
                              shutil.copyfile(
                                  os.path.join(
                                      uncompress_temp_dir, filename
                                  ),
                                  cache_path / filename,
                              )
                  else:
                      shutil.copyfile(uncompress_temp_dir, cache_path)
                  success = True
              except Exception as e:
                  logger.info(e)
                  raise e
              finally:
                  if not success:
                      if cache_path.exists():
                          if cache_path.is_file():
                              os.remove(cache_path)
                          else:
                              shutil.rmtree(cache_path)
                  os.close(fd)
                  os.remove(temp_filename)
                  if uncompress_temp_dir is None:
                      pass
                  elif os.path.isdir(uncompress_temp_dir):
                      shutil.rmtree(uncompress_temp_dir)
                  elif os.path.isfile(uncompress_temp_dir):
                      os.remove(uncompress_temp_dir)
              return get_filepath(cache_path)
          else:
              raise HTTPError(
                  f"Status code:{req.status_code}. Fail to download from {url}."
              )
  
imports: import os
  import re
  import shutil
  import tempfile
  from pathlib import Path
  from urllib.parse import urlparse
  import requests
  from requests import HTTPError
  from fastNLP.core.log import logger
  from rich.progress import Progress, BarColumn, DownloadColumn, TimeRemainingColumn, TimeElapsedColumn
label_desc: Use image node_id 9 for calling a global function with example usage: get_from_cache(url, cache_dir) and returns: get_filepath, get_filepath