class_docstr: Cache for model outputs.
code: def __init__(
      self,
      name: str,
      allow_concurrent_predictions: bool = True,
      cache_dir: Optional[str] = None,
  ):
      # TODO(lit-team): consider using a read/write lock, or setting timeouts if
      # contention becomes an issue.
      self._lock = threading.RLock()
      self._d: dict[CacheKey, Any] = dict()
      self._num_persisted = 0
      self._allow_concurrent_predictions = allow_concurrent_predictions
  
      self._cache_dir = cache_dir
      self._cache_loader = None
      if cache_dir:
          self._cache_loader = PickleCacheLoader(name, cache_dir)
  
      # A map of keys needing predictions to a lock for that model predict call.
      # Used for not duplicating concurrent prediction calls on the same inputs.
      self._pred_locks: dict[PredLockKey, threading.RLock] = dict()
  
imports: from collections.abc import Callable, Iterable
  import os
  import pickle
  import threading
  from typing import Any, Optional, Union
  from absl import logging
  from lit_nlp.api import dataset
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import serialize
label_desc: Use image node_id 1 to create a new PredsCache object from inherited base classes: object with example: obj = PredsCache(name, allow_concurrent_predictions, cache_dir)