docstr: Create Metric objects based off of the model_metrics data and add to cache
docstr_tok: ["Create","Metric","objects","based","off","of","the","model_metrics","data","and","add","to","cache"]
code: def initialize_cache(self) -> None:
      """
      Create Metric objects based off of the model_metrics data and add to cache
      """
      metrics_section = self._parse_metrics_section("model_metrics")
      if not metrics_section:
          raise merrors.MetricsCacheValueError(
              "Missing `model_metrics` specification"
          )
      for metric_type, metrics_list in metrics_section.items():
          try:
              metric_enum = MetricTypes(metric_type)
          except Exception as exc:
              raise merrors.MetricsCacheKeyError(
                  f"Invalid metric type: {exc}"
              )
  
          for metric in metrics_list:
              try:
                  metric_name = metric["name"]
                  unit = metric["unit"]
                  dimension_names = metric["dimensions"]
                  self.add_metric_to_cache(
                      metric_name=metric_name,
                      unit=unit,
                      dimension_names=dimension_names,
                      metric_type=metric_enum,
                  )
              except KeyError as k_err:
                  raise merrors.MetricsCacheKeyError(
                      f"Key not found in cache spec: {k_err}"
                  )
  
file_path: serve/ts/metrics/metric_cache_yaml_impl.py
imports: import logging
  import yaml
  import ts.metrics.metric_cache_errors
  from ts.metrics.caching_metric import CachingMetric
  from ts.metrics.metric_cache_abstract import MetricCacheAbstract
  from ts.metrics.metric_type_enum import MetricTypes
label_desc: Use image node_id 4 for calling the MetricsCacheYamlImpl obj's underlying member method code with example usage: obj.initialize_cache() without return types