docstr: Cache the given dataset if cache is enabled. Eventually waits for
  cache to be available (useful if another process is already
  computing cache) if provided wait flag is `True`.
  
  Parameters:
      dataset (Any):
          Dataset to be cached if cache is required.
      cache (str):
          Path of cache directory to be used, None if no cache.
      wait (bool):
          If caching is enabled, True is cache should be waited.
  
  Returns:
      Any:
          Cached dataset if needed, original dataset otherwise.
docstr_tok: ["Cache","the","given","dataset","if","cache","is","enabled",".","Eventually","waits","for","cache","to","be","available","(","useful","if","another","process","is","already","computing","cache",")","if","provided","wait","flag","is","`","True","`",".","Parameters",":","dataset","(","Any",")",":","Dataset","to","be","cached","if","cache","is","required",".","cache","(","str",")",":","Path","of","cache","directory","to","be","used",",","None","if","no","cache",".","wait","(","bool",")",":","If","caching","is","enabled",",","True","is","cache","should","be","waited",".","Returns",":","Any",":","Cached","dataset","if","needed",",","original","dataset","otherwise","."]
code: def cache(
      self, dataset: Any, cache: Optional[str], wait: bool
  ) -> Any:
      """
      Cache the given dataset if cache is enabled. Eventually waits for
      cache to be available (useful if another process is already
      computing cache) if provided wait flag is `True`.
  
      Parameters:
          dataset (Any):
              Dataset to be cached if cache is required.
          cache (str):
              Path of cache directory to be used, None if no cache.
          wait (bool):
              If caching is enabled, True is cache should be waited.
  
      Returns:
          Any:
              Cached dataset if needed, original dataset otherwise.
      """
      if cache is not None:
          if wait:
              while not exists(f"{cache}.index"):
                  logger.info(
                      f"Cache not available, wait {self.WAIT_PERIOD}"
                  )
                  time.sleep(self.WAIT_PERIOD)
          cache_path = os.path.split(cache)[0]
          os.makedirs(cache_path, exist_ok=True)
          return dataset.cache(cache)
      return dataset
  
imports: import os
  import time
  from os.path import exists
  from os.path import sep
  from typing import Any, Dict, List, Optional, Tuple
  import tensorflow
  from .audio.adapter import AudioAdapter
  from .audio.convertor import db_uint_spectrogram_to_gain, spectrogram_to_db_uint
  from .audio.spectrogram import compute_spectrogram_tf, random_pitch_shift, random_time_stretch
  from .utils.logging import logger
  from .utils.tensor import check_tensor_shape, dataset_from_csv, set_tensor_shape, sync_apply
label_desc: Use image node_id 14 for calling the DatasetBuilder obj's underlying member method code with example usage: obj.cache(dataset, cache, wait) and returns: dataset, dataset