class_docstr: StorageManager is helper interface for downloading & uploading files to supported remote storage
  Support remote servers: http(s)/S3/GS/Azure/File-System-Folder
  Cache is enabled by default for all downloaded remote urls/files
docstr: Extract cached file to cache folder
  :param str cached_file: local copy of archive file
  :param str name: name of the target file
  :param str cache_context: cache context id
  :param str target_folder: specify target path to use for archive extraction
  :param str cache_path_encoding: specify representation of the local path of the cached files,
      this will always point to local cache folder, even if we have direct access file.
      Used for extracting the cached archived based on cache_path_encoding
  :param bool force: Force archive extraction even if target folder exists
  :return: cached folder containing the extracted archive content
docstr_tok: ["Extract","cached","file","to","cache","folder",":","param","str","cached_file",":","local","copy","of","archive","file",":","param","str","name",":","name","of","the","target","file",":","param","str","cache_context",":","cache","context","id",":","param","str","target_folder",":","specify","target","path","to","use","for","archive","extraction",":","param","str","cache_path_encoding",":","specify","representation","of","the","local","path","of","the","cached","files",",","this","will","always","point","to","local","cache","folder",",","even","if","we","have","direct","access","file",".","Used","for","extracting","the","cached","archived","based","on","cache_path_encoding",":","param","bool","force",":","Force","archive","extraction","even","if","target","folder","exists",":","return",":","cached","folder","containing","the","extracted","archive","content"]
code: def _extract_to_cache(
      cls,
      cached_file,  # type: str
      name,  # type: str
      cache_context=None,  # type: Optional[str]
      target_folder=None,  # type: Optional[str]
      cache_path_encoding=None,  # type: Optional[str]
      force=False,  # type: bool
  ):
      # type: (...) -> str
      """
      Extract cached file to cache folder
      :param str cached_file: local copy of archive file
      :param str name: name of the target file
      :param str cache_context: cache context id
      :param str target_folder: specify target path to use for archive extraction
      :param str cache_path_encoding: specify representation of the local path of the cached files,
          this will always point to local cache folder, even if we have direct access file.
          Used for extracting the cached archived based on cache_path_encoding
      :param bool force: Force archive extraction even if target folder exists
      :return: cached folder containing the extracted archive content
      """
      if not cached_file:
          return cached_file
  
      cached_file = Path(cached_file)
      cache_path_encoding = (
          Path(cache_path_encoding) if cache_path_encoding else None
      )
  
      # we support zip and tar.gz files auto-extraction
      suffix = cached_file.suffix.lower()
      if suffix == ".gz":
          suffix = "".join(a.lower() for a in cached_file.suffixes[-2:])
  
      if suffix not in (".zip", ".tgz", ".tar.gz"):
          return str(cached_file)
  
      cache_folder = Path(cache_path_encoding or cached_file).parent
      archive_suffix = (cache_path_encoding or cached_file).name[
          : -len(suffix)
      ]
      name = encode_string_to_filename(name) if name else name
      if target_folder:
          target_folder = Path(target_folder)
      else:
          target_folder = (
              cache_folder
              / CacheManager.get_context_folder_lookup(
                  cache_context
              ).format(archive_suffix, name)
          )
  
      if target_folder.is_dir() and not force:
          # noinspection PyBroadException
          try:
              target_folder.touch(exist_ok=True)
              return target_folder.as_posix()
          except Exception:
              pass
  
      base_logger = LoggerRoot.get_base_logger()
      try:
          # if target folder exists, meaning this is forced ao we extract directly into target folder
          if target_folder.is_dir():
              temp_target_folder = target_folder
          else:
              temp_target_folder = cache_folder / "{0}_{1}_{2}".format(
                  target_folder.name,
                  time() * 1000,
                  str(random()).replace(".", ""),
              )
              temp_target_folder.mkdir(parents=True, exist_ok=True)
  
          if suffix == ".zip":
              zip_file = ZipFile(cached_file.as_posix())
              create_zip_directories(
                  zip_file, path=temp_target_folder.as_posix()
              )
              zip_file.extractall(path=temp_target_folder.as_posix())
          elif suffix == ".tar.gz":
              with tarfile.open(cached_file.as_posix()) as file:
                  safe_extract(file, temp_target_folder.as_posix())
          elif suffix == ".tgz":
              with tarfile.open(
                  cached_file.as_posix(), mode="r:gz"
              ) as file:
                  safe_extract(file, temp_target_folder.as_posix())
  
          if temp_target_folder != target_folder:
              # we assume we will have such folder if we already extract the file
              # noinspection PyBroadException
              try:
                  # if rename fails, it means that someone else already manged to extract the file, delete the current
                  # folder and return the already existing cached zip folder
                  shutil.move(
                      temp_target_folder.as_posix(),
                      target_folder.as_posix(),
                  )
              except Exception:
                  if target_folder.exists():
                      target_folder.touch(exist_ok=True)
                  else:
                      base_logger.warning(
                          "Failed renaming {0} to {1}".format(
                              temp_target_folder.as_posix(),
                              target_folder.as_posix(),
                          )
                      )
                  try:
                      shutil.rmtree(temp_target_folder.as_posix())
                  except Exception as ex:
                      base_logger.warning(
                          "Exception {}\nFailed deleting folder {}".format(
                              ex, temp_target_folder.as_posix()
                          )
                      )
      except Exception as ex:
          # failed extracting the file:
          base_logger.warning(
              "Exception {}\nFailed extracting zip file {}".format(
                  ex, cached_file.as_posix()
              )
          )
          # noinspection PyBroadException
          try:
              target_folder.rmdir()
          except Exception:
              pass
          return cached_file.as_posix()
      return target_folder.as_posix()
  
imports: import fnmatch
  import shutil
  import tarfile
  from multiprocessing.pool import ThreadPool
  from random import random
  from time import time
  from typing import List, Optional, Union
  from zipfile import ZipFile
  from pathlib2 import Path
  from .cache import CacheManager
  from .callbacks import ProgressReport
  from .helper import StorageHelper
  from .util import encode_string_to_filename, safe_extract, create_zip_directories
  from ..debugging.log import LoggerRoot
  from ..config import deferred_config
label_desc: Use image node_id 4 for calling the StorageManager obj's underlying member method code with example usage: obj._extract_to_cache(cls, cached_file, name, cache_context, target_folder, cache_path_encoding, force) and returns: target_folder, cached_file, str, target_folder, cached_file