def test_inference_cache(self):
        """
            Ensures that inference cache works for search but not add_docs when enabled
        """

        # Restart marqo with new max values
        new_models = ["hf/e5-large-v2"]
        index_name = "test_multiple_env_vars"
        utilities.rerun_marqo_with_env_vars(
            env_vars=[
                "-e", f"MARQO_MODELS_TO_PRELOAD={json.dumps(new_models)}",
                "-e", f"MARQO_INFERENCE_CACHE_SIZE=10",  # enable cache on inference side
                "-e", f"MARQO_API_INFERENCE_CACHE_SIZE=10",  # enable inference cache on api side
            ],
            calling_class=self.__class__.__name__
        )

        # Create index with same number of replicas and EF
        self.client.create_index(index_name=index_name, ann_parameters={
            "spaceType": 'prenormalized-angular', "parameters": {"efConstruction": 5000, "m": 16}}
        )

        # Assert correct EF const
        assert self.client.index(index_name).get_settings() \
                   ["annParameters"]["parameters"]["efConstruction"] == 5000

        # Assert correct models
        res = self.client.index(index_name).get_loaded_models()
        assert set([item["model_name"] for item in res["models"]]) == set(new_models)

        # Test inference cache
        telemetry_client = Client(**self.client_settings, return_telemetry=True)

        min_inference_time_ms = 8      # inference usually takes at least 8ms
        cache_reading_time_ms = 2      # if it hits cache, it's usually less than 2ms

        # Test search query's embedding is cached when inference cache is enabled
        for query in ["test", {"random": 1, "query": 2}]:
            with self.subTest(f"Search query: {query}"):
                # Single query
                # First search that misses cache should take longer
                r = telemetry_client.index(index_name).search(q=query)
                self.assertTrue(r["telemetry"]["timesMs"]["search.vector_inference_full_pipeline"] > min_inference_time_ms)
                
                # Run a few more times to make sure we populate it on API side cache as well as inference side cache
                self._run_in_threads(lambda client: client.index(index_name).search(q=query),
                                     max_workers=5, count=50)
                
                # Following searches should hit cache, average latency should be low
                inference_latency = self._run_in_threads(
                    lambda client: client.index(index_name).search(q=query),
                    max_workers=1, count=10, telemetry_name="search.vector_inference_full_pipeline")
                self.assertTrue(sum(inference_latency) / 10 < cache_reading_time_ms, inference_latency)

        # Test to ensure inference cache is not working for add_documents:
        with self.subTest("Add document"):
            # we do add doc one at a time to reduce the load on inference so the latency is small, we then verify
            # all the latency telemetry data points are larger than the min_inference_time_ms to verify cache is not
            # involved in this process
            inference_latency = self._run_in_threads(
                lambda client: client.index(index_name).add_documents([{"test": "test"}], tensor_fields=["test"]),
                max_workers=1, count=10, telemetry_name="add_documents.inference.all"
            )
            self.assertTrue(all([latency > min_inference_time_ms for latency in inference_latency]), inference_latency)

            Ensures that inference cache works for search but not add_docs when enabled
        
tests/api_tests/v1/tests/application_tests/test_env_var_changes.py