code: def set_and_log_cache(
      cache_instance: Cache,
      cache_key: str,
      cache_value: dict[str, Any],
      cache_timeout: int | None = None,
      datasource_uid: str | None = None,
  ) -> None:
      if isinstance(cache_instance.cache, NullCache):
          return
  
      timeout = (
          cache_timeout
          if cache_timeout is not None
          else app.config["CACHE_DEFAULT_TIMEOUT"]
      )
      try:
          dttm = datetime.utcnow().isoformat().split(".")[0]
          value = {**cache_value, "dttm": dttm}
          cache_instance.set(cache_key, value, timeout=timeout)
          stats_logger.incr("set_cache_key")
  
          if (
              datasource_uid
              and config["STORE_CACHE_KEYS_IN_METADATA_DB"]
          ):
              ck = CacheKey(
                  cache_key=cache_key,
                  cache_timeout=cache_timeout,
                  datasource_uid=datasource_uid,
              )
              db.session.add(ck)
      except Exception as ex:  # pylint: disable=broad-except
          # cache.set call can fail if the backend is down or if
          # the key is too large or whatever other reasons
          logger.warning("Could not cache key %s", cache_key)
          logger.exception(ex)
  
file_path: superset/superset/utils/cache.py
imports: from __future__ import annotations
  import inspect
  import logging
  from datetime import datetime, timedelta
  from functools import wraps
  from typing import Any, Callable, TYPE_CHECKING
  from flask import current_app, request
  from flask_caching import Cache
  from flask_caching.backends import NullCache
  from werkzeug.wrappers import Response
  from superset import db
  from superset.extensions import cache_manager
  from superset.models.cache import CacheKey
  from superset.utils.core import json_int_dttm_ser
  from superset.utils.hashing import md5_sha_from_dict
label_desc: Use image node_id 2 for calling a global function with example usage: set_and_log_cache(cache_instance, cache_key, cache_value, cache_timeout, datasource_uid) without return types