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: Adds key to cache using ``retrieval_function``.
  
  If value is provided, this is used instead. If the key is already in cache,
  the old element is removed. If the cache size exceeds the size limit, old
  elements are removed in order to meet the limit.
  
  Args:
      key (KeyType): Key in cache to retrieve.
      value (Optional[ValType]): Value to store for key. Default: None.
docstr_tok: ["Adds","key","to","cache","using","``","retrieval_function","``",".","If","value","is","provided",",","this","is","used","instead",".","If","the","key","is","already","in","cache",",","the","old","element","is","removed",".","If","the","cache","size","exceeds","the","size","limit",",","old","elements","are","removed","in","order","to","meet","the","limit",".","Args",":","key","(","KeyType",")",":","Key","in","cache","to","retrieve",".","value","(","Optional","[","ValType","]",")",":","Value","to","store","for","key",".","Default",":","None","."]
code: def put(self, key: KeyType, value: Optional[ValType] = None) -> None:
      """Adds key to cache using ``retrieval_function``.
  
      If value is provided, this is used instead. If the key is already in cache,
      the old element is removed. If the cache size exceeds the size limit, old
      elements are removed in order to meet the limit.
  
      Args:
          key (KeyType): Key in cache to retrieve.
          value (Optional[ValType]): Value to store for key. Default: None.
      """
      curr_value = None
      if key in self._lru_cache:
          curr_value = self._lru_cache.pop(key)
  
      while len(self._lru_cache) >= self._max_cache_items:
          self._lru_cache.popitem(last=False)
  
      if value is None:
          value = self._retrieval_function(  # type: ignore
              key=key, value=curr_value.element if curr_value else None
          )
  
      self._lru_cache[key] = self.Element(
          value=value,
          creation_time=datetime.datetime.now(tz=datetime.timezone.utc),
      )
  
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 6 for calling the LRUCache obj's underlying member method code with example usage: obj.put(key, value) without return types