code: def _get_from_cache(
      url: str,
      local_files_only: bool = False,
      progress_indicator: Optional[tqdm.tqdm] = None,
  ) -> str:
      """Downloads and returns the cache path to the content at the provided URL."""
      # TODO(b/254110131): Update to use FILE_CACHE_PATH_FLAG.value once the
      # integration tests in the TODO above have been updated for compatibility.
      lit_cache_dir = os.path.expanduser(FILE_CACHE_PATH_ENV)
      headers = {
          "user-agent": f"lit_nlp; python/{sys.version.split()[0]}"
      }
      etag: Optional[str] = None
      url_to_download: str = url
      os.makedirs(lit_cache_dir, exist_ok=True)
  
      # Attempt to get the ETag for this resource.
      if not local_files_only:
          try:
              head_response = _HTTP_SESSION.head(
                  url,
                  headers=headers,
                  stream=True,
                  allow_redirects=False,
              )
              head_response.raise_for_status()
              etag = str(
                  head_response.headers.get("X-Linked-Etag")
                  or head_response.headers.get("ETag")
              )
              if etag is None:
                  raise OSError(
                      "No ETag found for resource, reproducibility will be unreliable."
                  )
  
              # If the HEAD responds with a redirect, download from that URL if the
              # content is not in the cache, but use the original URL for the filename.
              # Otherwise, download from the original URL.
              if 300 <= head_response.status_code < 400:
                  url_to_download = str(
                      head_response.headers["Location"]
                  )
          except (
              requests.exceptions.ConnectionError,
              requests.exceptions.Timeout,
          ):
              pass  # etag is already None, url_to_download is already set.
  
      filename = filename_fom_url(url, etag=etag)
      cache_path = os.path.join(lit_cache_dir, filename)
  
      if os.path.exists(cache_path):
          logging.info("File %s exists in cache as %s", url, cache_path)
          return cache_path
      elif etag is None:
          raise ValueError(
              "Encountered a connection error and cannot find the requested files in"
              " the cached path. Please try again and ensure your Internet connection"
              " is on."
          )
  
      lock_path = cache_path + ".lock"
      with filelock.FileLock(lock_path):
          if os.path.exists(
              cache_path
          ):  # Download completed while activating lock.
              logging.info(
                  "File %s existing in cache as %s", url, cache_path
              )
              return (
                  cache_path  # Returning early will release the lock.
              )
  
          temp_file_manager = functools.partial(
              tempfile.NamedTemporaryFile,
              mode="wb",
              dir=lit_cache_dir,
              delete=False,
          )
          with temp_file_manager() as temp_file:
              logging.info("%s not found in cache.", url)
              _fetch_content(
                  url_to_download,
                  temp_file,
                  headers=headers,
                  progress_indicator=progress_indicator,
              )
              logging.info("%s downloaded to %s", url, temp_file.name)
  
          logging.info("Storing %s in cache at %s", url, cache_path)
          os.replace(temp_file.name, cache_path)
  
      return cache_path
  
imports: from collections.abc import Mapping
  import functools
  import hashlib
  import os
  import shutil
  import sys
  import tarfile
  import tempfile
  from typing import BinaryIO, Optional
  from urllib import parse
  import zipfile
  from absl import logging
  import filelock
  import requests
  import tqdm
label_desc: Use image node_id 3 for calling a global function with example usage: _get_from_cache(url, local_files_only, progress_indicator) and returns: cache_path, cache_path, cache_path