Home / Function/ test_global_cache_sync() — langchain Function Reference

test_global_cache_sync() — langchain Function Reference

Architecture documentation for the test_global_cache_sync() function in test_cache.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  482a4b87_fe55_f9c9_5d07_05dcbc31a740["test_global_cache_sync()"]
  51f634bf_713d_3f19_d694_5c6ef3e59c57["test_cache.py"]
  482a4b87_fe55_f9c9_5d07_05dcbc31a740 -->|defined in| 51f634bf_713d_3f19_d694_5c6ef3e59c57
  style 482a4b87_fe55_f9c9_5d07_05dcbc31a740 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/chat_models/test_cache.py lines 104–127

def test_global_cache_sync() -> None:
    """Test that the global cache gets populated when cache = True."""
    global_cache = InMemoryCache()
    try:
        set_llm_cache(global_cache)
        chat_model = FakeListChatModel(
            cache=True, responses=["hello", "goodbye", "meow", "woof"]
        )
        assert (chat_model.invoke("How are you?")).content == "hello"
        # If the cache works we should get the same response since
        # the prompt is the same
        assert (chat_model.invoke("How are you?")).content == "hello"
        # The global cache should be populated
        assert len(global_cache._cache) == 1
        llm_result = list(global_cache._cache.values())
        chat_generation = llm_result[0][0]
        assert isinstance(chat_generation, ChatGeneration)
        assert chat_generation.message.content == "hello"
        # Verify that another prompt will trigger the call to the model
        assert chat_model.invoke("nice").content == "goodbye"
        # The local cache should be populated
        assert len(global_cache._cache) == 2
    finally:
        set_llm_cache(None)

Subdomains

Frequently Asked Questions

What does test_global_cache_sync() do?
test_global_cache_sync() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py.
Where is test_global_cache_sync() defined?
test_global_cache_sync() is defined in libs/core/tests/unit_tests/language_models/chat_models/test_cache.py at line 104.

Analyze Your Own Codebase

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

Try Supermodel Free