class_docstr: Cache up to some maximum count given a grouping key.
  
  This object cache can e.g. be used to cache Ray Tune trainable actors
  given their resource requirements (reuse_actors=True).
  
  If the max number of cached objects for a grouping key is reached,
  no more objects for this group will be cached.
  
  However, if `may_keep_one=True`, one object (globally across all grouping
  keys) may be cached, even if the max number of objects is 0. This is to
  allow to cache an object if the max number of objects of this key
  will increase shortly after (as is the case e.g. in the Ray Tune control
  loop).
  
  Args:
      may_keep_one: If True, one object (globally) may be cached if no desired
          maximum objects are defined.
docstr: Return a generator over cached objects evicted from the cache.
  
  This method yields all cached objects that should be evicted from the
  cache for cleanup by the caller.
  
  If the number of max objects is lower than the number of
  cached objects for a given key, objects are evicted until
  the numbers are equal.
  
  If `max_keep_one=True` (and ``force_all=False``), one cached object
  may be retained.
  
  Objects are evicted FIFO.
  
  If ``force_all=True``, all objects are evicted.
  
  Args:
      force_all: If True, all objects are flushed. This takes precedence
          over ``keep_one``.
  
  Yields:
      Evicted objects to be cleaned up by caller.
code: def flush_cached_objects(
      self, force_all: bool = False
  ) -> Generator[U, None, None]:
      """Return a generator over cached objects evicted from the cache.
  
      This method yields all cached objects that should be evicted from the
      cache for cleanup by the caller.
  
      If the number of max objects is lower than the number of
      cached objects for a given key, objects are evicted until
      the numbers are equal.
  
      If `max_keep_one=True` (and ``force_all=False``), one cached object
      may be retained.
  
      Objects are evicted FIFO.
  
      If ``force_all=True``, all objects are evicted.
  
      Args:
          force_all: If True, all objects are flushed. This takes precedence
              over ``keep_one``.
  
      Yields:
          Evicted objects to be cleaned up by caller.
  
      """
      # If force_all=True, don't keep one.
      keep_one = self._may_keep_one and not force_all
  
      for key, objs in self._cached_objects.items():
          max_cached = (
              self._max_num_objects[key] if not force_all else 0
          )
  
          if (
              self._num_cached_objects == 1
              and keep_one
              # Only keep this object if we don't expect a different one
              and not any(v for v in self._max_num_objects.values())
          ):
              break
  
          while len(objs) > max_cached:
              self._num_cached_objects -= 1
              yield objs.pop(0)
  
file_path: ray/python/ray/tune/utils/object_cache.py
imports: from collections import defaultdict, Counter
  from typing import Dict, Generator, List, Optional, TypeVar
label_desc: Use image node_id 9 for calling the _ObjectCache obj's underlying member method code with example usage: obj.flush_cached_objects(force_all) without return types