docs: def save_target_in_cache(target: Target, build_context):
      """Save `target` to build cache for future reuse.
  
      The target hash is used to determine its cache location,
      where the target metadata and artifacts metadata are seriazlied to JSON.
      In addition, relevant artifacts produced by the target are copied under
      the artifacts cache dir by their content hash.
  
      TODO: pruning policy to limit cache size.
      """
      cache_dir = build_context.conf.get_cache_dir(target, build_context)
      if isdir(cache_dir):
          rmtree(cache_dir)
      makedirs(cache_dir)
      logger.debug('Saving target metadata in cache under {}', cache_dir)
      # write target metadata
      with open(join(cache_dir, 'target.json'), 'w') as meta_file:
          meta_file.write(target.json(build_context))
      # copy artifacts to artifact cache by hash
      artifacts = target.artifacts.get_all()
      artifact_hashes = {}
      for artifact_type, artifact_map in artifacts.items():
          if artifact_type in (AT.docker_image,):
              continue
          for dst_path, src_path in artifact_map.items():
              artifact_hashes[dst_path] = hash_tree(src_path)
              # not caching "app" artifacts, since they're part
              # of the source tree
              if artifact_type not in _NO_CACHE_TYPES:
                  copy_artifact(src_path, artifact_hashes[dst_path],
                                build_context.conf)
      # serialize target artifacts metadata + hashes
      artifacts_desc = {
          artifact_type.name:
          [{'dst': dst_path, 'src': src_path,
            'hash': artifact_hashes.get(dst_path)}
           for dst_path, src_path in artifact_map.items()]
          for artifact_type, artifact_map in artifacts.items()
      }
      with open(join(cache_dir, 'artifacts.json'), 'w') as artifacts_meta_file:
          artifacts_meta_file.write(json.dumps(artifacts_desc, indent=4,
                                               sort_keys=True))
      # copying the summary dict so I can modify it without mutating the target
      summary = dict(target.summary)
      summary['name'] = target.name
      summary['artifacts_hash'] = hash_tree(join(cache_dir, 'artifacts.json'))
      if summary.get('created') is None:
          summary['created'] = time()
      write_summary(summary, cache_dir)