docstr: Retrieves the cached result for the given arguments.
  
  Args:
      *args: args to litellm.completion() or embedding()
      **kwargs: kwargs to litellm.completion() or embedding()
  
  Returns:
      The cached result if it exists, otherwise None.
docstr_tok: ["Retrieves","the","cached","result","for","the","given","arguments",".","Args",":","*","args",":","args","to","litellm.completion","(",")","or","embedding","(",")","*","*","kwargs",":","kwargs","to","litellm.completion","(",")","or","embedding","(",")","Returns",":","The","cached","result","if","it","exists",",","otherwise","None","."]
code: def get_cache(self, *args, **kwargs):
      """
      Retrieves the cached result for the given arguments.
  
      Args:
          *args: args to litellm.completion() or embedding()
          **kwargs: kwargs to litellm.completion() or embedding()
  
      Returns:
          The cached result if it exists, otherwise None.
      """
      try:  # never block execution
          if "cache_key" in kwargs:
              cache_key = kwargs["cache_key"]
          else:
              cache_key = self.get_cache_key(*args, **kwargs)
          if cache_key is not None:
              cache_control_args = kwargs.get("cache", {})
              max_age = cache_control_args.get(
                  "s-max-age",
                  cache_control_args.get("s-maxage", float("inf")),
              )
              cached_result = self.cache.get_cache(cache_key)
              # Check if a timestamp was stored with the cached response
              if (
                  cached_result is not None
                  and isinstance(cached_result, dict)
                  and "timestamp" in cached_result
                  and max_age is not None
              ):
                  timestamp = cached_result["timestamp"]
                  current_time = time.time()
  
                  # Calculate age of the cached response
                  response_age = current_time - timestamp
  
                  # Check if the cached response is older than the max-age
                  if response_age > max_age:
                      print_verbose(
                          f"Cached response for key {cache_key} is too old. Max-age: {max_age}s, Age: {response_age}s"
                      )
                      return None  # Cached response is too old
  
                  # If the response is fresh, or there's no max-age requirement, return the cached response
                  # cached_response is in `b{} convert it to ModelResponse
                  cached_response = cached_result.get("response")
                  try:
                      if isinstance(cached_response, dict):
                          pass
                      else:
                          cached_response = json.loads(
                              cached_response
                          )  # Convert string to dictionary
                  except:
                      cached_response = ast.literal_eval(
                          cached_response
                      )
                  return cached_response
              return cached_result
      except Exception as e:
          print_verbose(
              f"An exception occurred: {traceback.format_exc()}"
          )
          return None
  
imports: import litellm
  import time, logging
  import json, traceback, ast, hashlib
  from typing import Optional, Literal, List, Union, Any
  from openai._models import BaseModel
label_desc: Use image node_id 4 for calling the Cache obj's underlying member method code with example usage: obj.get_cache() and returns: cached_result, None, cached_response, None