(self, metric_query: str, time_start: int, data: MetricsValuesDict)
Store items in the metrics cache; as discussed above, items newer than "five minutes ago" are not stored

        :param metric_query: the metric query to index data by
        :param items: mapping from metric name -> timeseries data, corresponding to the given query
Store items in the metrics cache; as discussed above, items newer than "five minutes ago" are not stored
Store items in the metrics cache ; as discussed above items newer than five minutes ago are not stored
def _cache_store(self, metric_query: str, time_start: int, data: MetricsValuesDict) -> None:
        """ Store items in the metrics cache; as discussed above, items newer than "five minutes ago" are not stored

        :param metric_query: the metric query to index data by
        :param items: mapping from metric name -> timeseries data, corresponding to the given query
        """
        centry = self._cache[metric_query]
        cache_size = len(centry.data)
        if cache_size == 0:
            centry.time_start = time_start

        min_time, max_time = float("inf"), 0
        five_minutes_ago = time.time() - _CACHE_DELAY
        should_invalidate = False
        stored_data: MetricsValuesDict = defaultdict(list)
        for metric_name, ts in data.items():
            cache_end = bisect(ts, (five_minutes_ago, float("-inf")))  # Don't cache the element exactly 5 minutes ago
            stored_data[metric_name] = ts[:cache_end]

            if ts:
                min_time = min(ts[0][0], min_time)
                max_time = max(ts[cache_end - 1][0], max_time)

                if len(centry.data[metric_name]) > 0 and ts[0][0] <= centry.data[metric_name][-1][0]:
                    logger.warning(
                        "First new item time {first} is before the last cache entry {last}; ".format(
                            first=ts[0][0], last=centry.data[metric_name][-1][0],
                        )
                        + "invalidating the cache"
                    )
                    should_invalidate = True

        if should_invalidate:
            self._cache[metric_query] = CacheEntry(time_start, stored_data)
        elif min_time <= max_time:
            logger.info(
                "Caching entries for {key} between {s} and {t}".format(key=metric_query, s=min_time, t=max_time,)
            )
            for metric_name, ts in stored_data.items():
                centry.data[metric_name] += ts
def _cache_store ( self , metric_query : str , time_start : int , data : MetricsValuesDict ) -> None : centry = self . _cache [ metric_query ] cache_size = len ( centry . data ) if cache_size == 0 : centry . time_start = time_start min_time , max_time = float ( "inf" ) , 0 five_minutes_ago = time . time ( ) - _CACHE_DELAY should_invalidate = False stored_data : MetricsValuesDict = defaultdict ( list ) for metric_name , ts in data . items ( ) : cache_end = bisect ( ts , ( five_minutes_ago , float ( "-inf" ) ) ) # Don't cache the element exactly 5 minutes ago stored_data [ metric_name ] = ts [ : cache_end ] if ts : min_time = min ( ts [ 0 ] [ 0 ] , min_time ) max_time = max ( ts [ cache_end - 1 ] [ 0 ] , max_time ) if len ( centry . data [ metric_name ] ) > 0 and ts [ 0 ] [ 0 ] <= centry . data [ metric_name ] [ - 1 ] [ 0 ] : logger . warning ( "First new item time {first} is before the last cache entry {last}; " . format ( first = ts [ 0 ] [ 0 ] , last = centry . data [ metric_name ] [ - 1 ] [ 0 ] , ) + "invalidating the cache" ) should_invalidate = True if should_invalidate : self . _cache [ metric_query ] = CacheEntry ( time_start , stored_data ) elif min_time <= max_time : logger . info ( "Caching entries for {key} between {s} and {t}" . format ( key = metric_query , s = min_time , t = max_time , ) ) for metric_name , ts in stored_data . items ( ) : centry . data [ metric_name ] += ts