code: def test_cache_invalidates_old_item():
      my_cache = cache.LRUCache[int, Union[int, str]](
          max_cache_items=10,
          expiration_horizon=datetime.timedelta(milliseconds=1),
          retrieval_function=retrieval_function,
      )
  
      mock_curr_time = datetime.datetime.fromtimestamp(
          1636730651.079551
      )
      with patch("datetime.datetime") as mock_datetime:
          mock_datetime.now.return_value = mock_curr_time
          my_cache.put(5)
          mock_datetime.now.return_value += datetime.timedelta(
              milliseconds=2
          )
          with pytest.raises(KeyError):
              my_cache.get(5, False)
  
      with patch("datetime.datetime") as mock_datetime:
          mock_datetime.now.return_value = mock_curr_time
          my_cache.put(5)
          mock_datetime.now.return_value += datetime.timedelta(
              milliseconds=0.5
          )
          assert my_cache.get(5, False) == (
              retrieval_function(key=5),
              True,
          )
  
file_path: sagemaker-python-sdk/tests/unit/sagemaker/utilities/test_cache.py
imports: from __future__ import absolute_import
  from typing import Optional, Union
  from mock.mock import MagicMock, patch
  import pytest
  from sagemaker.utilities import cache
  import datetime
label_desc: Use image node_id 3 for calling a global function with example usage: test_cache_invalidates_old_item() without return types