class_docstr: Tests for horovod.common.
class_docstr_tok: ["Tests","for","horovod.common","."]
docstr: Test that caching of expensive functions only computes values once.
docstr_tok: ["Test","that","caching","of","expensive","functions","only","computes","values","once","."]
code: def test_cache(self):
      """Test that caching of expensive functions only computes values once."""
      state = {}
  
      @_cache
      def fn():
          return state["key"]
  
      # Not yet cached
      state["key"] = 1
      value = fn()
      assert value == 1
  
      # Cached
      state["key"] = 2
      value = fn()
      assert value == 1
  
file_path: horovod/test/parallel/test_common.py
imports: import os
  import unittest
  import warnings
  from horovod.common.util import _cache, extension_available, gloo_built, mpi_built
label_desc: Use image node_id 7 for calling the CommonTests obj's underlying member method code with example usage: obj.test_cache() and returns: state