class_docstr: This class contains properties and methods for data source that can be read from cache files, which are utilized by data iterator.
  
  Args:
      data_source (:py:class:`DataSource <nnabla.utils.data_source.DataSource>`):
           Instance of DataSource class which provides data.
      cache_dir (str):
          Location of file_cache.
          If this value is None, :py:class:`.data_source.DataSourceWithFileCache`
          creates file caches implicitly on temporary directory and erases them all
          when data_iterator is finished.
          Otherwise, :py:class:`.data_source.DataSourceWithFileCache` keeps created cache.
          Default is None.
      cache_file_name_prefix (str):
          Beginning of the filenames of cache files.
          Default is 'cache'.
      shuffle (bool):
           Indicates whether the dataset is shuffled or not.
      rng (None or :obj:`numpy.random.RandomState`): Numpy random number
          generator.
class_docstr_tok: ["This","class","contains","properties","and","methods","for","data","source","that","can","be","read","from","cache","files",",","which","are","utilized","by","data","iterator",".","Args",":","data_source","(",":","py",":","class",":","`","DataSource","<","nnabla.utils.data_source.DataSource",">","`",")",":","Instance","of","DataSource","class","which","provides","data",".","cache_dir","(","str",")",":","Location","of","file_cache",".","If","this","value","is","None",",",":","py",":","class",":","`",".data_source.DataSourceWithFileCache","`","creates","file","caches","implicitly","on","temporary","directory","and","erases","them","all","when","data_iterator","is","finished",".","Otherwise",",",":","py",":","class",":","`",".data_source.DataSourceWithFileCache","`","keeps","created","cache",".","Default","is","None",".","cache_file_name_prefix","(","str",")",":","Beginning","of","the","filenames","of","cache","files",".","Default","is","'cache","'",".","shuffle","(","bool",")",":","Indicates","whether","the","dataset","is","shuffled","or","not",".","rng","(","None","or",":","obj",":","`","numpy.random.RandomState","`",")",":","Numpy","random","number","generator","."]
docstr: Store cache data into file.
  
  Data will be stored as hdf5 format, placed at config..
  Cache file name format is "cache_START_END.h5"
docstr_tok: ["Store","cache","data","into","file",".","Data","will","be","stored","as","hdf5","format",",","placed","at","config","..","Cache","file","name","format","is","``","cache_START_END.h5","''"]
code: def _save_cache_to_file(self):
      """
      Store cache data into file.
  
      Data will be stored as hdf5 format, placed at config..
      Cache file name format is "cache_START_END.h5"
      """
      if self._cache_dir is None:
          raise DataSourceWithFileCacheError(
              'Use this class with "with statement" if you don\'t specify cache dir.'
          )
      cache_data = OrderedDict()
  
      def get_data(args):
          pos = args[0]
          q = args[1]
          retry = 1
          while True:
              if retry > 10:
                  logger.log(
                      99,
                      "_get_current_data() retry count over give up.",
                  )
                  raise
              d = self._data_source._get_data(pos)
              if d is not None:
                  break
              logger.log(
                  99,
                  "_get_data() fails. retrying count {}/10.".format(
                      retry
                  ),
              )
              retry += 1
  
          q.put((pos, d))
  
      q = Queue()
      with closing(ThreadPool(processes=self._num_of_threads)) as pool:
          pool.map(
              get_data, [(pos, q) for pos in self._cache_positions]
          )
  
      while len(cache_data) < len(self._cache_positions):
          index, data = q.get()
          cache_data[index] = data
      start_position = self.position - len(cache_data) + 1
      end_position = self.position
      cache_filename = os.path.join(
          self._cache_dir,
          "{}_{:08d}_{:08d}{}".format(
              self._cache_file_name_prefix,
              start_position,
              end_position,
              self._cache_file_format,
          ),
      )
  
      data = OrderedDict([(n, []) for n in self._data_source.variables])
      for pos in sorted(cache_data):
          cd = cache_data[pos]
          for i, n in enumerate(self._data_source.variables):
              if isinstance(cd[i], numpy.ndarray):
                  d = cd[i]
              else:
                  d = numpy.array(cd[i]).astype(numpy.float32)
              data[n].append(d)
  
      logger.info("Creating cache file {}".format(cache_filename))
      try:
          if self._cache_file_format == ".h5":
              h5 = h5py.File(cache_filename, "w")
              for k, v in data.items():
                  h5.create_dataset(k, data=v)
              h5.close()
          else:
              retry_count = 1
              is_create_cache_incomplete = True
              while is_create_cache_incomplete:
                  try:
                      with open(cache_filename, "wb") as f:
                          for v in data.values():
                              numpy.save(f, v)
                      is_create_cache_incomplete = False
                  except OSError:
                      retry_count += 1
                      if retry_count > 10:
                          raise
                      logger.info(
                          "Creating cache retry {}/10".format(
                              retry_count
                          )
                      )
      except:
          logger.critical(
              "An error occurred while creating cache file from dataset."
          )
          for k, v in data.items():
              size = v[0].shape
              for d in v:
                  if size != d.shape:
                      logger.critical(
                          'The sizes of data "{}" are not the same. ({} != {})'.format(
                              k, size, d.shape
                          )
                      )
          raise
  
      self._cache_file_names.append(cache_filename)
      self._cache_file_order.append(len(self._cache_file_order))
      self._cache_file_data_orders.append(list(range(len(cache_data))))
      self._cache_positions = []
  
imports: import warnings
  from collections import OrderedDict
  from contextlib import closing
  from multiprocessing import Queue
  from multiprocessing.pool import ThreadPool
  from shutil import rmtree
  import abc
  import atexit
  import warnings
  import h5py
  import csv
  import numpy
  import os
  import six
  import tempfile
  import threading
  from nnabla.config import nnabla_config
  from nnabla.logger import logger
  from nnabla.utils.progress import progress
  from nnabla.utils.communicator_util import single_or_rankzero
  from .data_source_loader import FileReader
label_desc: Use image node_id 1 for calling the DataSourceWithFileCache obj's underlying member method code with example usage: obj._save_cache_to_file() without return types