class_docstr: Manages cached values for a single st.cache_resource function.
docstr: Write a value and associated messages to the cache.
docstr_tok: ["Write","a","value","and","associated","messages","to","the","cache","."]
code: def write_result(
      self, key: str, value: Any, messages: list[MsgData]
  ) -> None:
      """Write a value and associated messages to the cache."""
      ctx = get_script_run_ctx()
      if ctx is None:
          return
  
      main_id = st._main.id
      sidebar_id = st.sidebar.id
      if self.allow_widgets:
          widgets = {
              msg.widget_metadata.widget_id
              for msg in messages
              if isinstance(msg, ElementMsgData)
              and msg.widget_metadata is not None
          }
      else:
          widgets = set()
  
      with self._mem_cache_lock:
          try:
              multi_results = self._mem_cache[key]
          except KeyError:
              multi_results = MultiCacheResults(
                  widget_ids=widgets, results={}
              )
  
          multi_results.widget_ids.update(widgets)
          widget_key = multi_results.get_current_widget_key(
              ctx, CacheType.RESOURCE
          )
  
          result = CachedResult(value, messages, main_id, sidebar_id)
          multi_results.results[widget_key] = result
          self._mem_cache[key] = multi_results
  
imports: from __future__ import annotations
  import math
  import threading
  import types
  from datetime import timedelta
  from typing import Any, Callable, TypeVar, cast, overload
  from cachetools import TTLCache
  from typing_extensions import TypeAlias
  import streamlit
  from streamlit.deprecation_util import show_deprecation_warning
  from streamlit.logger import get_logger
  from streamlit.runtime.caching import cache_utils
  from streamlit.runtime.caching.cache_errors import 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.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
  from streamlit.vendor.pympler.asizeof import asizeof
label_desc: Use image node_id 5 for calling the ResourceCache obj's underlying member method code with example usage: obj.write_result(key, value, messages) without return types