class_docstr: The streaming dataset can be used once your data have been optimised using the DatasetOptimiser class.
class_docstr_tok: ["The","streaming","dataset","can","be","used","once","your","data","have","been","optimised","using","the","DatasetOptimiser","class","."]
code: def _create_cache(self, worker_env: _WorkerEnv) -> Cache:
      env = Environment(
          dist_env=self.distributed_env, worker_env=worker_env
      )
  
      if _should_replace_path(self.input_dir.path):
          # FIXME: Remove the `shard_rank` from the cache_path to enable reloading chunks for the second epoch
          # without paying the cost of re-download
          cache_path = _try_create_cache_dir(
              input_dir=self.input_dir.path
              if self.input_dir.path
              else self.input_dir.url,
              shard_rank=env.shard_rank,
          )
          if cache_path is not None:
              self.input_dir.path = cache_path
  
      cache = Cache(
          input_dir=self.input_dir,
          item_loader=self.item_loader,
          chunk_bytes=1,
          serializers=self.serializers,
          max_cache_size=self.max_cache_size,
      )
      cache._reader._try_load_config()
  
      if not cache.filled:
          raise ValueError(
              f"The provided dataset `{self.input_dir}` doesn't contain any {_INDEX_FILENAME} file."
              " HINT: Did you successfully optimize a dataset to the provided `input_dir`?"
          )
  
      return cache
  
imports: import hashlib
  import os
  from dataclasses import dataclass
  from time import time
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  from torch.utils.data import IterableDataset, get_worker_info
  from lightning.data.streaming import Cache
  from lightning.data.streaming.constants import _DEFAULT_CACHE_DIR, _INDEX_FILENAME, _LIGHTNING_CLOUD_LATEST
  from lightning.data.streaming.item_loader import BaseItemLoader
  from lightning.data.streaming.sampler import ChunkedIndex
  from lightning.data.streaming.serializers import Serializer
  from lightning.data.streaming.shuffle import FullShuffle, NoShuffle, Shuffle
  from lightning.data.utilities.env import Environment, _DistributedEnv, _WorkerEnv
label_desc: Use image node_id 2 for calling the StreamingDataset obj's underlying member method code with example usage: obj._create_cache(worker_env) and returns: cache