class_docstr: A utility for storing messages generated by `st` commands called inside
  a cached function.
  
  Data is stored in a thread-local object, so it's safe to use an instance
  of this class across multiple threads.
class_docstr_tok: ["A","utility","for","storing","messages","generated","by","`","st","`","commands","called","inside","a","cached","function",".","Data","is","stored","in","a","thread-local","object",",","so","it","'s","safe","to","use","an","instance","of","this","class","across","multiple","threads","."]
docstr: Context manager that should wrap the invocation of a cached function.
  It allows us to track any `st.foo` messages that are generated from inside the function
  for playback during cache retrieval.
code: def calling_cached_function(
      self, func: types.FunctionType, allow_widgets: bool
  ) -> Iterator[None]:
      """Context manager that should wrap the invocation of a cached function.
      It allows us to track any `st.foo` messages that are generated from inside the function
      for playback during cache retrieval.
      """
      self._cached_func_stack.append(func)
      self._cached_message_stack.append([])
      self._seen_dg_stack.append(set())
      if allow_widgets:
          self._allow_widgets += 1
      try:
          yield
      finally:
          self._cached_func_stack.pop()
          self._most_recent_messages = self._cached_message_stack.pop()
          self._seen_dg_stack.pop()
          if allow_widgets:
              self._allow_widgets -= 1
  
imports: from __future__ import annotations
  import contextlib
  import hashlib
  import threading
  import types
  from dataclasses import dataclass
  from typing import TYPE_CHECKING, Any, Iterator, Union
  from google.protobuf.message import Message
  from typing_extensions import Protocol, runtime_checkable
  import streamlit
  from streamlit import runtime, util
  from streamlit.elements import NONWIDGET_ELEMENTS, WIDGETS
  from streamlit.logger import get_logger
  from streamlit.proto.Block_pb2 import Block
  from streamlit.runtime.caching.cache_errors import CachedStFunctionWarning, CacheReplayClosureError
  from streamlit.runtime.caching.cache_type import CacheType
  from streamlit.runtime.caching.hashing import update_hash
  from streamlit.runtime.scriptrunner.script_run_context import ScriptRunContext, get_script_run_ctx
  from streamlit.runtime.state.common import WidgetMetadata
  from streamlit.util import HASHLIB_KWARGS
label_desc: Use image node_id 3 for calling the CachedMessageReplayContext obj's underlying member method code with example usage: obj.calling_cached_function(func, allow_widgets) without return types