class_docstr: Class that implements LRU cache with expiring items.
  
  LRU caches remove items in a FIFO manner, such that the oldest
  items to be used are the first to be removed.
  If you attempt to retrieve a cache item that is older than the
  expiration time, the item will be invalidated.
class_docstr_tok: ["Class","that","implements","LRU","cache","with","expiring","items",".","LRU","caches","remove","items","in","a","FIFO","manner",",","such","that","the","oldest","items","to","be","used","are","the","first","to","be","removed",".","If","you","attempt","to","retrieve","a","cache","item","that","is","older","than","the","expiration","time",",","the","item","will","be","invalidated","."]
docstr: Returns value from cache corresponding to key.
  
  If ``fail_on_old_value``, a KeyError is raised instead of a new value
      getting fetched.
  
  Args:
      key (KeyType): Key in cache to retrieve.
      fail_on_old_value (bool): True if a KeyError is raised when the cache value
          is old.
  
  Raises:
      KeyError: If key is not in cache or if key is old in cache
          and fail_on_old_value is True.
docstr_tok: ["Returns","value","from","cache","corresponding","to","key",".","If","``","fail_on_old_value","``",",","a","KeyError","is","raised","instead","of","a","new","value","getting","fetched",".","Args",":","key","(","KeyType",")",":","Key","in","cache","to","retrieve",".","fail_on_old_value","(","bool",")",":","True","if","a","KeyError","is","raised","when","the","cache","value","is","old",".","Raises",":","KeyError",":","If","key","is","not","in","cache","or","if","key","is","old","in","cache","and","fail_on_old_value","is","True","."]
code: def _get_item(self, key: KeyType, fail_on_old_value: bool) -> ValType:
      """Returns value from cache corresponding to key.
  
      If ``fail_on_old_value``, a KeyError is raised instead of a new value
          getting fetched.
  
      Args:
          key (KeyType): Key in cache to retrieve.
          fail_on_old_value (bool): True if a KeyError is raised when the cache value
              is old.
  
      Raises:
          KeyError: If key is not in cache or if key is old in cache
              and fail_on_old_value is True.
      """
      try:
          element = self._lru_cache.pop(key)
          curr_time = datetime.datetime.now(tz=datetime.timezone.utc)
          element_age = curr_time - element.creation_time
          if element_age > self._expiration_horizon:
              if fail_on_old_value:
                  raise KeyError(
                      f"{key} has aged beyond allowed time {self._expiration_horizon}. "
                      f"Element created at {element.creation_time}."
                  )
              element.value = self._retrieval_function(  # type: ignore
                  key=key, value=element.value
              )
              element.creation_time = curr_time
          self._lru_cache[key] = element
          return element.value
      except KeyError:
          raise KeyError(f"{key} not found in LRUCache!")
  
file_path: sagemaker-python-sdk/src/sagemaker/utilities/cache.py
imports: from __future__ import absolute_import
  import datetime
  import collections
  from typing import Tuple, TypeVar, Generic, Callable, Optional
label_desc: Use image node_id 7 for calling the LRUCache obj's underlying member method code with example usage: obj._get_item(key, fail_on_old_value) and returns: element