docstr: The Cache enables to optimise dataset format for cloud training. This is done by grouping several elements
  together in order to accelerate fetching.
  
  Arguments:
      input_dir: The path to where the chunks will be or are stored.
      compression: The name of the algorithm to reduce the size of the chunks.
      chunk_bytes: The maximum number of bytes within a chunk.
      chunk_size: The maximum number of items within a chunk.
      item_loader: The object responsible to generate the chunk intervals and load an item froma chunk.
      max_cache_size: The maximum cache size used by the reader when fetching the chunks.
      serializers: Provide your own serializers.
docstr_tok: ["The","Cache","enables","to","optimise","dataset","format","for","cloud","training",".","This","is","done","by","grouping","several","elements","together","in","order","to","accelerate","fetching",".","Arguments",":","input_dir",":","The","path","to","where","the","chunks","will","be","or","are","stored",".","compression",":","The","name","of","the","algorithm","to","reduce","the","size","of","the","chunks",".","chunk_bytes",":","The","maximum","number","of","bytes","within","a","chunk",".","chunk_size",":","The","maximum","number","of","items","within","a","chunk",".","item_loader",":","The","object","responsible","to","generate","the","chunk","intervals","and","load","an","item","froma","chunk",".","max_cache_size",":","The","maximum","cache","size","used","by","the","reader","when","fetching","the","chunks",".","serializers",":","Provide","your","own","serializers","."]
code: def __init__(
      self,
      input_dir: Optional[Union[str, Dir]],
      compression: Optional[str] = None,
      chunk_size: Optional[int] = None,
      chunk_bytes: Optional[Union[int, str]] = None,
      item_loader: Optional[BaseItemLoader] = None,
      max_cache_size: Union[int, str] = "100GB",
      serializers: Optional[Dict[str, Serializer]] = None,
  ):
      """The Cache enables to optimise dataset format for cloud training. This is done by grouping several elements
      together in order to accelerate fetching.
  
      Arguments:
          input_dir: The path to where the chunks will be or are stored.
          compression: The name of the algorithm to reduce the size of the chunks.
          chunk_bytes: The maximum number of bytes within a chunk.
          chunk_size: The maximum number of items within a chunk.
          item_loader: The object responsible to generate the chunk intervals and load an item froma chunk.
          max_cache_size: The maximum cache size used by the reader when fetching the chunks.
          serializers: Provide your own serializers.
  
      """
      super().__init__()
      if not _TORCH_GREATER_EQUAL_2_1_0:
          raise ModuleNotFoundError(
              "PyTorch version 2.1 or higher is required to use the cache."
          )
  
      if not _LIGHTNING_CLOUD_LATEST:
          raise ModuleNotFoundError(
              "Lightning Cloud latest is required to use the cache."
          )
  
      input_dir = _resolve_dir(input_dir)
      self._cache_dir = input_dir.path
      self._writer = BinaryWriter(
          self._cache_dir,
          chunk_size=chunk_size,
          chunk_bytes=chunk_bytes,
          compression=compression,
          serializers=serializers,
      )
      self._reader = BinaryReader(
          self._cache_dir,
          max_cache_size=_convert_bytes_to_int(max_cache_size)
          if isinstance(max_cache_size, str)
          else max_cache_size,
          remote_input_dir=input_dir.url,
          compression=compression,
          item_loader=item_loader,
          serializers=serializers,
      )
      self._is_done = False
      self._distributed_env = _DistributedEnv.detect()
      self._rank: Optional[int] = None
  
imports: import logging
  import os
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Tuple, Union
  from lightning.data.streaming.constants import _INDEX_FILENAME, _LIGHTNING_CLOUD_LATEST, _TORCH_GREATER_EQUAL_2_1_0
  from lightning.data.streaming.item_loader import BaseItemLoader
  from lightning.data.streaming.reader import BinaryReader
  from lightning.data.streaming.sampler import ChunkedIndex
  from lightning.data.streaming.serializers import Serializer
  from lightning.data.streaming.writer import BinaryWriter
  from lightning.data.utilities.env import _DistributedEnv, _WorkerEnv
  from lightning.data.utilities.format import _convert_bytes_to_int
label_desc: Use image node_id 1 to create a new Cache object  with example: obj = Cache(input_dir, compression, chunk_size, chunk_bytes, item_loader, max_cache_size, serializers)