class_docstr: Maps policy IDs to Policy objects.
  
  Thereby, keeps n policies in memory and - when capacity is reached -
  writes the least recently used to disk. This allows adding 100s of
  policies to a Algorithm for league-based setups w/o running out of memory.
docstr: Writes the least-recently used policy's state to the Ray object store.
  
  Also closes the session - if applicable - of the stashed policy.
  
  Returns:
      The least-recently used policy, that just got removed from the cache.
docstr_tok: ["Writes","the","least-recently","used","policy","'s","state","to","the","Ray","object","store",".","Also","closes","the","session","-","if","applicable","-","of","the","stashed","policy",".","Returns",":","The","least-recently","used","policy",",","that","just","got","removed","from","the","cache","."]
code: def _stash_least_used_policy(self) -> Policy:
      """Writes the least-recently used policy's state to the Ray object store.
  
      Also closes the session - if applicable - of the stashed policy.
  
      Returns:
          The least-recently used policy, that just got removed from the cache.
      """
      # Get policy's state for writing to object store.
      dropped_policy_id = self._deque.popleft()
      assert dropped_policy_id in self.cache
      policy = self.cache[dropped_policy_id]
      policy_state = policy.get_state()
  
      # If we don't simply swap out vs an existing policy:
      # Close the tf session, if any.
      if not self.policy_states_are_swappable:
          self._close_session(policy)
  
      # Remove from memory. This will clear the tf Graph as well.
      del self.cache[dropped_policy_id]
  
      # Store state in Ray object store.
      self._policy_state_refs[dropped_policy_id] = ray.put(policy_state)
  
      # Return the just removed policy, in case it's needed by the caller.
      return policy
  
imports: from collections import deque
  import threading
  from typing import Dict, Set
  import logging
  import ray
  from ray.rllib.policy.policy import Policy
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.deprecation import deprecation_warning
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.threading import with_lock
  from ray.rllib.utils.typing import PolicyID
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 14 for calling the PolicyMap obj's underlying member method code with example usage: obj._stash_least_used_policy() and returns: policy