class_docstr: Writes a cache object that can be read by ReadAnalysisCacheFromFS.
  
  Given a cache collection, this writes it to the configured directory.
  If the configured directory already contains cache, this will merge the new
  cache with the old.
  NOTE: This merging of cache is determined at beam graph construction time,
  so the cache must already exist there when constructing this.
class_docstr_tok: ["Writes","a","cache","object","that","can","be","read","by","ReadAnalysisCacheFromFS",".","Given","a","cache","collection",",","this","writes","it","to","the","configured","directory",".","If","the","configured","directory","already","contains","cache",",","this","will","merge","the","new","cache","with","the","old",".","NOTE",":","This","merging","of","cache","is","determined","at","beam","graph","construction","time",",","so","the","cache","must","already","exist","there","when","constructing","this","."]
code: def _write_cache(
      self, manifest_file, dataset_key_index, dataset_key_dir, cache
  ):
      manifest = manifest_file.read()
      start_cache_idx = max(manifest.values()) + 1 if manifest else 0
  
      dataset_identifier = f"AnalysisIndex{dataset_key_index}"
      cache_is_written = []
      for cache_key_idx, (cache_entry_key, cache_pcoll) in enumerate(
          cache.cache_dict.items(), start_cache_idx
      ):
          cache_identifier = f"CacheKeyIndex{cache_key_idx}"
          path = os.path.join(dataset_key_dir, str(cache_key_idx))
          manifest[cache_entry_key] = cache_key_idx
          cache_is_written.append(
              cache_pcoll
              | f"Write[{dataset_identifier}][{cache_identifier}]"
              >> self._sink(path)
          )
      if cache.metadata is not None:
          cache_is_written.append(
              cache.metadata
              | f"WriteMetadata[{dataset_identifier}]"
              >> _WriteMetadata(dataset_key_dir)
          )
  
      manifest_file.write(manifest)
      return cache_is_written
  
imports: import os
  import pickle
  import re
  import sys
  from typing import Iterable, Mapping, List, Optional, Union, Tuple
  import apache_beam
  import tensorflow
  from tfx_bsl.types import tfx_namedtuple
label_desc: Use image node_id 3 for calling the WriteAnalysisCacheToFS obj's underlying member method code with example usage: obj._write_cache(manifest_file, dataset_key_index, dataset_key_dir, cache) and returns: cache_is_written