class_docstr: Manages all DataCache instances
class_docstr_tok: ["Manages","all","DataCache","instances"]
docstr: Return the mem cache for the given key.
  
  If it doesn't exist, create a new one with the given params.
docstr_tok: ["Return","the","mem","cache","for","the","given","key",".","If","it","does","n't","exist",",","create","a","new","one","with","the","given","params","."]
code: def get_cache(
      self,
      key: str,
      persist: CachePersistType,
      max_entries: int | None,
      ttl: int | float | timedelta | str | None,
      display_name: str,
      allow_widgets: bool,
  ) -> DataCache:
      """Return the mem cache for the given key.
  
      If it doesn't exist, create a new one with the given params.
      """
  
      ttl_seconds = ttl_to_seconds(ttl, coerce_none_to_inf=False)
  
      # Get the existing cache, if it exists, and validate that its params
      # haven't changed.
      with self._caches_lock:
          cache = self._function_caches.get(key)
          if (
              cache is not None
              and cache.ttl_seconds == ttl_seconds
              and cache.max_entries == max_entries
              and cache.persist == persist
          ):
              return cache
  
          # Close the existing cache's storage, if it exists.
          if cache is not None:
              _LOGGER.debug(
                  "Closing existing DataCache storage "
                  "(key=%s, persist=%s, max_entries=%s, ttl=%s) "
                  "before creating new one with different params",
                  key,
                  persist,
                  max_entries,
                  ttl,
              )
              cache.storage.close()
  
          # Create a new cache object and put it in our dict
          _LOGGER.debug(
              "Creating new DataCache (key=%s, persist=%s, max_entries=%s, ttl=%s)",
              key,
              persist,
              max_entries,
              ttl,
          )
  
          cache_context = self.create_cache_storage_context(
              function_key=key,
              function_name=display_name,
              ttl_seconds=ttl_seconds,
              max_entries=max_entries,
              persist=persist,
          )
          cache_storage_manager = self.get_storage_manager()
          storage = cache_storage_manager.create(cache_context)
  
          cache = DataCache(
              key=key,
              storage=storage,
              persist=persist,
              max_entries=max_entries,
              ttl_seconds=ttl_seconds,
              display_name=display_name,
              allow_widgets=allow_widgets,
          )
          self._function_caches[key] = cache
          return cache
  
imports: from __future__ import annotations
  import pickle
  import threading
  import types
  from datetime import timedelta
  from typing import Any, Callable, TypeVar, Union, cast, overload
  from typing_extensions import Literal, TypeAlias
  import streamlit
  from streamlit import runtime
  from streamlit.deprecation_util import show_deprecation_warning
  from streamlit.errors import StreamlitAPIException
  from streamlit.logger import get_logger
  from streamlit.runtime.caching.cache_errors import CacheError, CacheKeyNotFoundError
  from streamlit.runtime.caching.cache_type import CacheType
  from streamlit.runtime.caching.cache_utils import Cache, CachedFuncInfo, make_cached_func_wrapper, ttl_to_seconds
  from streamlit.runtime.caching.cached_message_replay import CachedMessageReplayContext, CachedResult, ElementMsgData, MsgData, MultiCacheResults
  from streamlit.runtime.caching.hashing import HashFuncsDict
  from streamlit.runtime.caching.storage import CacheStorage, CacheStorageContext, CacheStorageError, CacheStorageKeyNotFoundError, CacheStorageManager
  from streamlit.runtime.caching.storage.cache_storage_protocol import InvalidCacheStorageContext
  from streamlit.runtime.caching.storage.dummy_cache_storage import MemoryCacheStorageManager
  from streamlit.runtime.metrics_util import gather_metrics
  from streamlit.runtime.scriptrunner.script_run_context import get_script_run_ctx
  from streamlit.runtime.stats import CacheStat, CacheStatsProvider, group_stats
label_desc: Use image node_id 2 for calling the DataCaches obj's underlying member method code with example usage: obj.get_cache(key, persist, max_entries, ttl, display_name, allow_widgets) and returns: cache, cache