Home / Class/ AsyncCacheTestSuite Class — langchain Architecture

AsyncCacheTestSuite Class — langchain Architecture

Architecture documentation for the AsyncCacheTestSuite class in cache.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  dd98e6ff_00d0_3b82_14a9_72605570e8eb["AsyncCacheTestSuite"]
  2d95e59f_5168_1366_c8c2_e21e157938b5["BaseStandardTests"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|extends| 2d95e59f_5168_1366_c8c2_e21e157938b5
  92201723_18d0_c857_8abf_4c639e01e4d6["cache.py"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|defined in| 92201723_18d0_c857_8abf_4c639e01e4d6
  bc72c5d2_8b05_f375_8482_2ace601b17ba["cache()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| bc72c5d2_8b05_f375_8482_2ace601b17ba
  2a3e33e1_e71c_06e5_5392_f2f9206ddeb8["get_sample_prompt()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 2a3e33e1_e71c_06e5_5392_f2f9206ddeb8
  14583cf3_5b32_1fba_4ae7_aee3aa24ec91["get_sample_llm_string()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 14583cf3_5b32_1fba_4ae7_aee3aa24ec91
  5066233f_040d_a2c5_d6b2_a9f4c7ebce26["get_sample_generation()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 5066233f_040d_a2c5_d6b2_a9f4c7ebce26
  8da37386_8c5b_fdfe_7f97_5f6851f97c35["test_cache_is_empty()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 8da37386_8c5b_fdfe_7f97_5f6851f97c35
  6295c3aa_934e_1dfc_3c89_29ce182bbe83["test_update_cache()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 6295c3aa_934e_1dfc_3c89_29ce182bbe83
  6c8a3256_0907_b9f3_d83e_430739ea0785["test_cache_still_empty()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 6c8a3256_0907_b9f3_d83e_430739ea0785
  d3ab26e3_9b49_398b_63b9_10e3fda33568["test_clear_cache()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| d3ab26e3_9b49_398b_63b9_10e3fda33568
  273f557c_65a0_c991_fb5d_09b66e611568["test_cache_miss()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 273f557c_65a0_c991_fb5d_09b66e611568
  0b654711_852d_1996_3250_f1440088ef40["test_cache_hit()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 0b654711_852d_1996_3250_f1440088ef40
  66a31794_5818_494b_b74d_c6a33fc2cbc6["test_update_cache_with_multiple_generations()"]
  dd98e6ff_00d0_3b82_14a9_72605570e8eb -->|method| 66a31794_5818_494b_b74d_c6a33fc2cbc6

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/integration_tests/cache.py lines 109–207

class AsyncCacheTestSuite(BaseStandardTests):
    """Test suite for checking the `BaseCache` API of a caching layer for LLMs.

    Verifies the basic caching API of a caching layer for LLMs.

    The test suite is designed for synchronous caching layers.

    Implementers should subclass this test suite and provide a fixture that returns an
    empty cache for each test.
    """

    @abstractmethod
    @pytest.fixture
    async def cache(self) -> BaseCache:
        """Get the cache class to test.

        The returned cache should be EMPTY.
        """

    def get_sample_prompt(self) -> str:
        """Return a sample prompt for testing."""
        return "Sample prompt for testing."

    def get_sample_llm_string(self) -> str:
        """Return a sample LLM string for testing."""
        return "Sample LLM string configuration."

    def get_sample_generation(self) -> Generation:
        """Return a sample `Generation` object for testing."""
        return Generation(
            text="Sample generated text.",
            generation_info={"reason": "test"},
        )

    async def test_cache_is_empty(self, cache: BaseCache) -> None:
        """Test that the cache is empty."""
        assert (
            await cache.alookup(self.get_sample_prompt(), self.get_sample_llm_string())
            is None
        )

    async def test_update_cache(self, cache: BaseCache) -> None:
        """Test updating the cache."""
        prompt = self.get_sample_prompt()
        llm_string = self.get_sample_llm_string()
        generation = self.get_sample_generation()
        await cache.aupdate(prompt, llm_string, [generation])
        assert await cache.alookup(prompt, llm_string) == [generation]

    async def test_cache_still_empty(self, cache: BaseCache) -> None:
        """Test that the cache is still empty.

        This test should follow a test that updates the cache.

        This just verifies that the fixture is set up properly to be empty after each
        test.
        """
        assert (
            await cache.alookup(self.get_sample_prompt(), self.get_sample_llm_string())
            is None
        )

    async def test_clear_cache(self, cache: BaseCache) -> None:
        """Test clearing the cache."""
        prompt = self.get_sample_prompt()
        llm_string = self.get_sample_llm_string()
        generation = self.get_sample_generation()
        await cache.aupdate(prompt, llm_string, [generation])
        await cache.aclear()
        assert await cache.alookup(prompt, llm_string) is None

    async def test_cache_miss(self, cache: BaseCache) -> None:
        """Test cache miss."""
        assert (
            await cache.alookup("Nonexistent prompt", self.get_sample_llm_string())
            is None
        )

    async def test_cache_hit(self, cache: BaseCache) -> None:
        """Test cache hit."""
        prompt = self.get_sample_prompt()

Frequently Asked Questions

What is the AsyncCacheTestSuite class?
AsyncCacheTestSuite is a class in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/cache.py.
Where is AsyncCacheTestSuite defined?
AsyncCacheTestSuite is defined in libs/standard-tests/langchain_tests/integration_tests/cache.py at line 109.
What does AsyncCacheTestSuite extend?
AsyncCacheTestSuite extends BaseStandardTests.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free