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: Cache object for a given key.
  
  This will put the object into a cache, assuming the number
  of cached objects for this key is less than the number of
  max objects for this key.
  
  An exception is made if `max_keep_one=True` and no other
  objects are cached globally. In that case, the object can
  still be cached.
  
  Args:
      key: Group key.
      obj: Object to cache.
  
  Returns:
      True if the object has been cached. False otherwise.
code: def cache_object(self, key: T, obj: U) -> bool:
      """Cache object for a given key.
  
      This will put the object into a cache, assuming the number
      of cached objects for this key is less than the number of
      max objects for this key.
  
      An exception is made if `max_keep_one=True` and no other
      objects are cached globally. In that case, the object can
      still be cached.
  
      Args:
          key: Group key.
          obj: Object to cache.
  
      Returns:
          True if the object has been cached. False otherwise.
  
      """
      # If we have more objects cached already than we desire
      if len(self._cached_objects[key]) >= self._max_num_objects[key]:
          # If may_keep_one is False, never cache
          if not self._may_keep_one:
              return False
  
          # If we have more than one other cached object, don't cache
          if self._num_cached_objects > 0:
              return False
  
          # If any other objects are expected to be cached, don't cache
          if any(v for v in self._max_num_objects.values()):
              return False
  
      # Otherwise, cache (for now).
  
      self._cached_objects[key].append(obj)
      self._num_cached_objects += 1
      return True
  
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 7 for calling the _ObjectCache obj's underlying member method code with example usage: obj.cache_object(key, obj) and returns: True, False, False, False