docstr: Create a new metric and add into cache. Override existing metric with same name if present.
  
  Parameters
  ----------
  metric_name str
      Name of metric
  unit str
      unit can be one of ms, percent, count, MB, GB or a generic string
  dimension_names list
      list of dimension name strings for the metric
  metric_type MetricTypes
      Type of metric Counter, Gauge, Histogram
  Returns
  -------
  newly created Metrics object
docstr_tok: ["Create","a","new","metric","and","add","into","cache",".","Override","existing","metric","with","same","name","if","present",".","Parameters","--","--","--","--","--","metric_name","str","Name","of","metric","unit","str","unit","can","be","one","of","ms",",","percent",",","count",",","MB",",","GB","or","a","generic","string","dimension_names","list","list","of","dimension","name","strings","for","the","metric","metric_type","MetricTypes","Type","of","metric","Counter",",","Gauge",",","Histogram","Returns","--","--","--","-","newly","created","Metrics","object"]
code: def add_metric_to_cache(
      self,
      metric_name: str,
      unit: str,
      dimension_names: list = [],
      metric_type: MetricTypes = MetricTypes.COUNTER,
  ) -> CachingMetric:
      """
      Create a new metric and add into cache. Override existing metric with same name if present.
  
      Parameters
      ----------
      metric_name str
          Name of metric
      unit str
          unit can be one of ms, percent, count, MB, GB or a generic string
      dimension_names list
          list of dimension name strings for the metric
      metric_type MetricTypes
          Type of metric Counter, Gauge, Histogram
      Returns
      -------
      newly created Metrics object
      """
      self._check_type(metric_name, str, "`metric_name` must be a str")
      self._check_type(unit, str, "`unit` must be a str")
      self._check_type(
          metric_type,
          MetricTypes,
          "`metric_type` must be a MetricTypes enum",
      )
      if dimension_names:
          self._check_type(
              dimension_names,
              list,
              "`dimension_names` should be a list of dimension name strings",
          )
      if metric_type not in self.cache.keys():
          self.cache[metric_type] = {}
      metric = CachingMetric(
          metric_name=metric_name,
          unit=unit,
          dimension_names=dimension_names,
          metric_type=metric_type,
      )
      if metric_name in self.cache[metric_type].keys():
          logging.warning(
              f"Overriding existing key {metric_type}:{metric_name}"
          )
      self.cache[metric_type][metric_name] = metric
      return metric
  
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 5 for calling the MetricsCacheYamlImpl obj's underlying member method code with example usage: obj.add_metric_to_cache(metric_name, unit, dimension_names, metric_type) and returns: metric