SyncCacheTestSuite Class — langchain Architecture
Architecture documentation for the SyncCacheTestSuite class in cache.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f46c1166_d92e_0c5e_3d9f_3cd853667546["SyncCacheTestSuite"] 2d95e59f_5168_1366_c8c2_e21e157938b5["BaseStandardTests"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|extends| 2d95e59f_5168_1366_c8c2_e21e157938b5 92201723_18d0_c857_8abf_4c639e01e4d6["cache.py"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|defined in| 92201723_18d0_c857_8abf_4c639e01e4d6 ea1071de_e55a_551b_0e42_8bfe95f5ce8b["cache()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| ea1071de_e55a_551b_0e42_8bfe95f5ce8b 8d2633ab_22ae_8b55_41da_de32bc54c05f["get_sample_prompt()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| 8d2633ab_22ae_8b55_41da_de32bc54c05f 73de4c1f_97e5_fadb_2568_565ef7c0927e["get_sample_llm_string()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| 73de4c1f_97e5_fadb_2568_565ef7c0927e afca8049_aeb6_d0d1_fcb2_9d4914a1742a["get_sample_generation()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| afca8049_aeb6_d0d1_fcb2_9d4914a1742a d664daa9_c3b9_6710_3822_4fd3d5aa3b0c["test_cache_is_empty()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| d664daa9_c3b9_6710_3822_4fd3d5aa3b0c 89e3d63e_7272_d2a0_575f_8204a52e1d36["test_update_cache()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| 89e3d63e_7272_d2a0_575f_8204a52e1d36 692c9fae_1e5f_c00a_4469_7523675c4219["test_cache_still_empty()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| 692c9fae_1e5f_c00a_4469_7523675c4219 cc8ae0a1_99d1_4958_3bdc_9b43d4f6b5a4["test_clear_cache()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| cc8ae0a1_99d1_4958_3bdc_9b43d4f6b5a4 6a8193d2_73bc_17fc_8516_818a6d097bbf["test_cache_miss()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| 6a8193d2_73bc_17fc_8516_818a6d097bbf 5c4679c2_68a4_7681_afd2_58b10af8b21b["test_cache_hit()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| 5c4679c2_68a4_7681_afd2_58b10af8b21b 2f7e1b0c_2916_10eb_96a8_3df2d20987f8["test_update_cache_with_multiple_generations()"] f46c1166_d92e_0c5e_3d9f_3cd853667546 -->|method| 2f7e1b0c_2916_10eb_96a8_3df2d20987f8
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/cache.py lines 16–106
class SyncCacheTestSuite(BaseStandardTests):
"""Test suite for checking the `BaseCache` API of a caching layer for LLMs.
This test suite 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
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"},
)
def test_cache_is_empty(self, cache: BaseCache) -> None:
"""Test that the cache is empty."""
assert (
cache.lookup(self.get_sample_prompt(), self.get_sample_llm_string()) is None
)
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()
cache.update(prompt, llm_string, [generation])
assert cache.lookup(prompt, llm_string) == [generation]
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 (
cache.lookup(self.get_sample_prompt(), self.get_sample_llm_string()) is None
)
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()
cache.update(prompt, llm_string, [generation])
cache.clear()
assert cache.lookup(prompt, llm_string) is None
def test_cache_miss(self, cache: BaseCache) -> None:
"""Test cache miss."""
assert cache.lookup("Nonexistent prompt", self.get_sample_llm_string()) is None
def test_cache_hit(self, cache: BaseCache) -> None:
"""Test cache hit."""
prompt = self.get_sample_prompt()
llm_string = self.get_sample_llm_string()
generation = self.get_sample_generation()
cache.update(prompt, llm_string, [generation])
assert cache.lookup(prompt, llm_string) == [generation]
Extends
Source
Frequently Asked Questions
What is the SyncCacheTestSuite class?
SyncCacheTestSuite is a class in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/cache.py.
Where is SyncCacheTestSuite defined?
SyncCacheTestSuite is defined in libs/standard-tests/langchain_tests/integration_tests/cache.py at line 16.
What does SyncCacheTestSuite extend?
SyncCacheTestSuite extends BaseStandardTests.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free