code: def maybe_cached_dataset(config, name, generating_func):
      """Returns cached dataset instance if caching of datasets is enabled and a valid dataset is available.
  
      We speedup test startup time by caching previously generated synthetic dataset.
      This is useful while developing for tests reruns, but can be dangerous since we can
      get stale results when petastorm code participating in dataset generation is used.
  
      :param config: request.config object.
      :param name: name of the cached dataset. Used as a cache key.
      :param generating_func: This function will be called (`generating_func()`) if dataset cache is disabled or
        no valid dataset is found in cache.
      :return:
      """
      if config.getoption(_CACHE_FAKE_DATASET_OPTION):
          cache_key = "{}_{}".format(name, "PY2" if six.PY2 else "PY3")
          serialized = config.cache.get(cache_key, None)
          dataset = (
              pickle.loads(b64decode(serialized))
              if serialized
              else None
          )
          if not dataset or not os.path.exists(dataset.path):
              dataset = generating_func()
              config.cache.set(
                  cache_key,
                  b64encode(pickle.dumps(dataset)).decode("ascii"),
              )
          else:
              logger.warning(
                  "CAUTION: %s HAS BEEN USED. USING %s CACHED TEST DATASET! MAYBE STALE!",
                  _CACHE_FAKE_DATASET_OPTION,
                  name,
              )
      else:
          dataset = generating_func()
  
      return dataset
  
imports: import logging
  import os
  import pickle
  import tempfile
  from base64 import b64encode, b64decode
  from collections import namedtuple
  import pytest
  import six
  from petastorm.spark import spark_dataset_converter, SparkDatasetConverter
  from petastorm.tests.test_common import create_test_dataset, create_test_scalar_dataset, create_many_columns_non_petastorm_dataset
  from pyspark.sql import SparkSession
label_desc: Use image node_id 3 for calling a global function with example usage: maybe_cached_dataset(config, name, generating_func) and returns: dataset